Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
Dim gr As System.Drawing.Graphics
Dim mycolor As System.Drawing.Color
gr = DirectCast(sender, Panel).CreateGraphics
Dim mybitmap As New Bitmap(DirectCast(sender, Panel).Width, DirectCast(sender, Panel).Height, gr)
gr = Graphics.FromImage(mybitmap)
gr.CopyFromScreen(DirectCast(sender, Panel).Location, Point.Empty, New Size(mybitmap.Width, mybitmap.Height), CopyPixelOperation.SourceCopy)
mycolor = mybitmap.GetPixel(e.X, e.Y)
End Sub
Public Class Form1
Private Sub PictureBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim colorval As Long
Dim map1 As New Bitmap("C:\chemin fichier image.jpg")
colorval = map1.GetPixel(e.X, e.Y).ToArgb 'code long
' Conversion code long en RGB
Dim g As Byte = CByte(Int((colorval And &HFF00) / &H100))
Dim b As Byte = CByte((Int((colorval And &HFF0000) / &H10000)))
Dim r As Byte = CByte((Int(colorval And &HFF)))
Dim text As String = _
String.Format("red: {0}, green: {1}, blue: {2}", New Object() {r, g, b})
MsgBox(text) 'code RGB
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = Image.FromFile("C:\chemin fichier image.jpg")
End Sub
End Class
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" _
(ByVal hdc As Int32, ByVal x As Int32, ByVal y As Int32) As Int32
Dim xx, yy As Long
Sub Form2_MouseClick...
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim pixelColor As Color
Using g As Graphics = Graphics.FromHwnd(Me.Handle)
pixelColor = ColorTranslator.FromWin32(GetPixel(g.GetHdc(), xx, yy))
End Using
HScrollBar1.Value = pixelColor.R
HScrollBar2.Value = pixelColor.G
HScrollBar3.Value = pixelColor.B
End Sub
Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" _
(ByVal hdc As Int32, ByVal x As Int32, ByVal y As Int32) As Int32
Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Dim pixelColor As Color
Using gr As Graphics = Graphics.FromHwnd(Me.Handle)
pixelColor = ColorTranslator.FromWin32(GetPixel(CInt(gr.GetHdc()), CInt(e.X), CInt(e.Y)))
End Using
Dim r As Byte = (pixelColor.R)
Dim g As Byte = (pixelColor.G)
Dim b As Byte = (pixelColor.B)
Dim text As String = _
String.Format("red: {0}, green: {1}, blue: {2}", New Object() {r, g, b})
MsgBox(text) 'code RGB
End Sub