Couleur pixel

Résolu
cs_aurel16 Messages postés 75 Date d'inscription samedi 17 septembre 2005 Statut Membre Dernière intervention 29 octobre 2010 - 9 sept. 2008 à 20:24
cs_aurel16 Messages postés 75 Date d'inscription samedi 17 septembre 2005 Statut Membre Dernière intervention 29 octobre 2010 - 18 sept. 2008 à 20:22
Bonjour,

Comment fait-on pour savoir la couleur ( RVB ) d'un certain pixel d'une image affichée dans une picturebox ?

merci de vos reponses

5 réponses

gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
9 sept. 2008 à 21:03


_

Public




Shared




Function

CreateDC(

ByVal

strDriver

As




String

,

ByVal

strDevice

As




String

,

ByVal

strOutput

As




String

,

ByVal

pData

As

IntPtr)

As

IntPtr

End




Function


_

Public




Shared




Function

DeleteDC(

ByVal

hdc

As

IntPtr)

As




Boolean






End




Function


_

Public




Shared




Function

GetPixel(

ByVal

hdc

As

IntPtr,

ByVal

x

As




Integer

,

ByVal

y

As




Integer

)

As




Integer






End




Function






Private




Sub

PixelColor()

Dim

pt

As

Point

Try


pt =


New

Point(Convert.ToInt32(txtX.Text), Convert.ToInt32(txtY.Text))

Catch


pt =


New

Point(0, 0)

End




Try 






' Call the three external functions.






Dim

clr

As

Color

Dim

hdcScreen

As

IntPtr = CreateDC(

"Display"

,

Nothing

,

Nothing

, IntPtr.Zero)

Dim

cr

As




Integer

= GetPixel(hdcScreen, pt.X, pt.Y)DeleteDC(hdcScreen)

' Convert a Win32 COLORREF to a .NET Color object


clr = Color.FromArgb((cr


And

&HFF), (cr

And

&HFF00) >> 8, (cr

And

&HFF0000) >> 16)panel1.BackColor = clrtxtX.Text = pt.X.ToString()txtY.Text = pt.Y.ToString()

'hexa ou base 10






If

rbBase10.Checked =

True




Then


txtR.Text = clr.R.ToString(


"000"

)txtG.Text = clr.G.ToString(

"000"

)txtB.Text = clr.B.ToString(

"000"

)txtCopy.Text = txtR.Text &

","

& txtG.Text &

","

& txtB.Text

Else


txtR.Text = clr.R.ToString(


"X2"

)txtG.Text = clr.G.ToString(

"X2"

)txtB.Text = clr.B.ToString(

"X2"

)txtCopy.Text =

"#"

& txtR.Text + txtG.Text + txtB.Text

End




If






'copie dans le presse papier


txtCopy.SelectAll()




If




Me

.chkAutoCopy.Checked =

True




Then


txtCopy.Copy()




End




If






End




Sub
avec ce code tu as tout ce qu'il te fautBonjour chez vous !
3
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
9 sept. 2008 à 21:07
Bonjour,
Est_ce que l'utilisation de :
Le_nom_de_ta_picturebox.GetPixel(X,Y) ne ferit pas l'affaire, pour relever la valeur du pixeln sous VB.Net  ?
 Une fois cette valeur connue, sa décomposition en 3 valeurs R,G,B est facile et on la trouve partout...
3
Kevin.Ory Messages postés 840 Date d'inscription mercredi 22 octobre 2003 Statut Membre Dernière intervention 7 janvier 2009 11
10 sept. 2008 à 14:12
Loll ouais, joli ton code Gilardg mais un peu long

Il faut d'abord faire un cast Image => Bitmap pour avoir accès à GetPixel, comme ceci:
Dim MyBitmap As Bitmap = Me.PictureBox1.Image
Dim PixelColor As Color = MyBitmap.GetPixel(X, Y)

Mais attention, niveau perf c'est archi-nul. Pour faire du traitement sur des pixels, vaut mieux passer par un Bitmap.LockBits
3
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
10 sept. 2008 à 16:04
c'est pas de moi j'ai repique sur un color picker en c#




 










Bonjour chez vous !
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_aurel16 Messages postés 75 Date d'inscription samedi 17 septembre 2005 Statut Membre Dernière intervention 29 octobre 2010
18 sept. 2008 à 20:22
merci a tous
0
Rejoignez-nous