OVH Cloud OVH Cloud

GetPixel

2 réponses
Avatar
Nicolas
Bonjour,

Sur mon form j'ai une Picture1, un Command1 et 3 labels.

Voici mon code :

Private Declare Function SetPixel Lib "gdi32" (ByVal hdc
As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor
As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc
As Long, ByVal X As Long, ByVal Y As Long) As Long


Private Sub Command1_Click()
i = 0
For X = 0 To 255
For Y = 0 To 255
z = X + Y
SetPixel Me.Picture1.hdc, X, Y, RGB(X, Y, z)
Next Y
Next X

End Sub

Private Sub Form_Load()

End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Me.lblX = X
Me.lblY = Y
Me.lblCouleur = GetPixel(Me.Picture1.hdc, X, Y)
End Sub

Quelqu'un peut il me dire pourquoi dans lblCouleur j'ai
toujours -1 ?

Merci

Nicolas

2 réponses

Avatar
François Picalausa
"Nicolas" a écrit dans le message de
news:002601c3c57a$0dbe6790$
Bonjour,

Sur mon form j'ai une Picture1, un Command1 et 3 labels.

Voici mon code :

Private Declare Function SetPixel Lib "gdi32" (ByVal hdc
As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor
As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc
As Long, ByVal X As Long, ByVal Y As Long) As Long


Private Sub Command1_Click()
i = 0
For X = 0 To 255
For Y = 0 To 255
z = X + Y
SetPixel Me.Picture1.hdc, X, Y, RGB(X, Y, z)
Next Y
Next X

End Sub

Private Sub Form_Load()

End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Me.lblX = X
Me.lblY = Y
Me.lblCouleur = GetPixel(Me.Picture1.hdc, X, Y)
End Sub

Quelqu'un peut il me dire pourquoi dans lblCouleur j'ai
toujours -1 ?



Bonjour/soir,

Probablement parce que tu te situe en dehors de limites...

Essaye dans Private Sub Form_Load():
Picture1.ScaleMode = 3

Pour éviter qu'il ne travaille en twips.

Une autre solution est d'utiliser Point et/ou Pset à la place de Get et
SetPixel.

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com
Avatar
Nicolas
Super, ça marche, c'était exactement ça !

Merci beaucoup.

Merci d'ailleurs à tous ceux qui prennent le temps de lire
mes posts et qui me répondent, c'est une aide vraiment
précieuse !!!

@+

Nicolas