Private Function Capturectrl(ByVal ctrl As Control) As Bitmap Dim memoryImage As Bitmap Dim memoryGraphics As Graphics memoryImage = Nothing Dim mygraphics As Graphics = ctrl.CreateGraphics() Dim s As Size = ctrl.Size If TypeOf ctrl Is Form AndAlso DirectCast(ctrl, Form).FormBorderStyle <> FormBorderStyle.None Then memoryImage = New Bitmap(s.Width - 10, s.Height - (SystemInformation.FrameBorderSize.Width + 6 + SystemInformation.CaptionHeight), mygraphics) memoryGraphics = Graphics.FromImage(memoryImage) memoryGraphics.CopyFromScreen(0, (SystemInformation.FrameBorderSize.Width + 0 + SystemInformation.CaptionHeight), 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy) Else memoryImage = New Bitmap(s.Width, s.Height, mygraphics) memoryGraphics = Graphics.FromImage(memoryImage) memoryGraphics.CopyFromScreen(ctrl.Left, ctrl.Top, 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy) End If Return memoryImage End Function Private Function readbitmap(ByVal imagescan As Bitmap) As List(Of Color) Dim listpixel As New List(Of Color) Dim colorpixel As Color Try For row As Integer = 0 To imagescan.Width - 1 For col As Integer = 0 To imagescan.Height - 1 colorpixel = imagescan.GetPixel(row, col) listpixel.Add(colorpixel) Next Next Catch ex As Exception MessageBox.Show(ex.Message) End Try Return listpixel End Function Dim lispixel As New List(Of Color) lispixel = readbitmap(Capturectrl(Me))
... Comment relever les couleurs des pixels...
Dim r, v, b As String ' copie r = Mid((Me.BackColor.ToArgb() And &HFFFFFF&).ToString("X"), 1, 2) v = Mid((Me.BackColor.ToArgb() And &HFFFFFF&).ToString("X"), 3, 2) b = Mid((Me.BackColor.ToArgb() And &HFFFFFF&).ToString("X"), 5, 2) Dim r1 As Int32 = Convert.ToInt32(rougeS, 16) ' r, v, b Dim v1 As Int32 = Convert.ToInt32(vertS, 16) Dim b1 As Int32 = Convert.ToInt32(bleuS, 16)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub GetPixel_Example(ByVal e As PaintEventArgs) Dim myBitmap As New Bitmap("Grapes.jpg") Dim pixelColor As Color = myBitmap.GetPixel(50, 50) Dim pixelBrush As New SolidBrush(pixelColor) e.Graphics.FillRectangle(pixelBrush, 0, 0, 100, 100) End Sub
Dim formbitmap As New Bitmap(Me.Width, Me.Height) Me.DrawToBitmap(formbitmap, New Rectangle(0, 0, Me.Width, Me.Width)) Dim lispixel As New List(Of Color) lispixel = readbitmap(formbitmap)