API GetBitmapBits et SetBitmapBits

cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 - 11 févr. 2003 à 20:12
harddisk Messages postés 54 Date d'inscription vendredi 28 décembre 2001 Statut Membre Dernière intervention 13 mai 2007 - 4 juin 2003 à 17:36
Bonjour,

Copiez collez le code qui suit dans un form et cliquez sur une zone du form pour voir la lenteur de la brush:

Ce code est vraiment lent, même compilé.

J'aimerais le rendre plus rapide grâce aux API GetBitmapBits et SetBitmapBits ( ou autre, cela ne me dérange pas du moment que c'est rapide) mais je n'y arrive pas ( il me dessine des ovales avec des traits plein de bugs )

Pouvez vous m'envoyer le code corrigé svp ou m'aider pour que ce code soit nettement plus rapide que GetPixel et SetPixel ?

merci d'avance

mail : jeanpierre.rossetto@club-internet.fr

***********************************************
***********************************************
***************CODE A COPIER COLLER*************
***********************************************
***********************************************

Option Explicit

'precision airbrush 2.0 PSet by dafhi
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Type AirbrushSystem
radius As Single
brush_height As Single
brush_slope As Single
height_Sq As Single
End Type

Private Type AirbrushStruct
Red As Byte
Green As Byte
Blue As Byte
Pressure As Byte
definition As Single
diameter As Single
bErasing As Boolean
Sys As AirbrushSystem
End Type

Dim Airbrush As AirbrushStruct

Dim Alpha&

Private Const B255 As Byte = 255

Dim FormActivateLoops&

Private Sub Form_Load()
ScaleMode = vbPixels
End Sub

Private Sub Form_Activate()
Dim y1!
Dim dy!

Randomize

y1 = 80
BackColor = vbWhite

'New setting for Form_MouseMove
Airbrush.Pressure = 255
Airbrush.diameter = 50
Airbrush.definition = 1

End Sub

Private Sub BlitAirbrush(Obj1 As Object, px!, py!)
Dim DrawX&
Dim DrawY&
Dim DrawLeft&
Dim DrawRight&
Dim DrawBot&
Dim DrawTop&
Dim AddDrawWidth&
Dim AddDrawHeight&
Dim ClipWidthLeft&
Dim ClipWidthBot&
Dim delta_left!
Dim delta_x!
Dim delta_y!
Dim delta_ySq!
Dim deltas_Sq_sum!
Dim BGR2&
Dim BGRed As Long
Dim BGGrn As Long
Dim BGBlu As Long

Dim SWm1& 'ScaleWidth - 1
Dim SHm1&

If Airbrush.diameter > 0! Then

SWm1 = Obj1.ScaleWidth - 1
SHm1 = Obj1.ScaleHeight - 1

Airbrush.Sys.radius = Airbrush.diameter / 2
'If you think of a cross section of a cone,
'brush_height and brush_slope become visible

Airbrush.Sys.brush_height = Airbrush.Pressure * Airbrush.definition
Airbrush.Sys.brush_slope = Airbrush.Sys.brush_height / Airbrush.Sys.radius

'setting up the rect that will contain the entire brush
DrawLeft = RealRound(px - Airbrush.Sys.radius)
DrawBot = RealRound(py - Airbrush.Sys.radius)
DrawRight = RealRound(px + Airbrush.Sys.radius)
DrawTop = RealRound(py + Airbrush.Sys.radius)

'Clipping

If DrawLeft < 0 Then DrawLeft = 0
If DrawBot < 0 Then DrawBot = 0
If DrawRight > SWm1 Then DrawRight = SWm1
If DrawTop > SHm1 Then DrawTop = SHm1

'initial delta x with each new scanline

delta_left = (DrawLeft - px) * Airbrush.Sys.brush_slope
delta_y = (DrawBot - py) * Airbrush.Sys.brush_slope

For DrawY = DrawBot To DrawTop
delta_ySq = delta_y * delta_y
delta_x = delta_left
For DrawX = DrawLeft To DrawRight
deltas_Sq_sum = delta_x * delta_x + delta_ySq

Alpha = Airbrush.Sys.brush_height - Sqr(deltas_Sq_sum)

If Alpha > 0 Then

If Alpha > Airbrush.Pressure Then
Alpha = Airbrush.Pressure
End If

BGR2 = GetPixel(Obj1.hdc, DrawX, DrawY)
BGRed = BGR2 And &HFF
BGGrn = (BGR2 And &HFF00&) / 256&
BGBlu = (BGR2 And &HFF0000) / 65536
SetPixelV Obj1.hdc, DrawX, DrawY, RGB(BGRed + Alpha * (Airbrush.Red - BGRed) / B255, BGGrn + Alpha * (Airbrush.Green - BGGrn) / B255, BGBlu + Alpha * (Airbrush.Blue - BGBlu) / B255)

End If

delta_x = delta_x + Airbrush.Sys.brush_slope

Next DrawX

delta_y = delta_y + Airbrush.Sys.brush_slope
Next DrawY
End If
Obj1.Refresh
End Sub
Private Function RealRound(sngVal As Single) As Single

'This function rounds .5 up

RealRound = Int(sngVal)If sngVal - RealRound >0.5! Then RealRound RealRound + 1&

End Function

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
Airbrush.Red = 0
Airbrush.Green = 0
Airbrush.Blue = 0
Airbrush.definition = 1
Airbrush.diameter = 255
Airbrush.Pressure = 255
BlitAirbrush Form1, x, y
End If
End Sub

1 réponse

harddisk Messages postés 54 Date d'inscription vendredi 28 décembre 2001 Statut Membre Dernière intervention 13 mai 2007
4 juin 2003 à 17:36
moi aussi je suis intéréssé par une m'éthode plus rapide que get pixel.Si tu as la réponse tu peut m'envoyer un message(avec vbfrance)?
Merci
0
Rejoignez-nous