سلام
در مورد کار کردن با پیکسل های یک bitmap باید این نکته رو در نظر بگیری که فراخوانی توابع Getpixel و setpixel یک مقدار زمان بر هست.
برای اجتناب از این کار باید بیت های اون رو lock کنی،اونوقت پردازش سریعتر انجام میشه.
مثلا قطعه کد زیر میاد مقدار تمام پیکسل های یک bitmap رو بعد از bit lock کردن اون چک میکه:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bmp As New System.Drawing.Bitmap(picViewer1.Image) 'IMAGE FROM PICTURE BOX...
Call LockBitmap(bmp) 'LOCKING BITMAP
Dim RedValue As Int32
Dim GreenValue As Int32
Dim BlueValue As Int32
Dim l As Integer = 0 ' Pixel position
For x = 0 To bmp.Width - 1 'Pixels start with 0 so we need Height - 1
For y = 0 To bmp.Height - 1
l = ((bmp.Width * 3 * y) + (x * 3)) ' pixel is made of 3 parts (RGB colors)
RedValue = rgbValues(l)
GreenValue = rgbValues(l + 1)
BlueValue = rgbValues(l + 2)
If RedValue > 250 AndAlso GreenValue > 250 AndAlso BlueValue > 250 Then
Msgbox("Pixel is of a white color...")
ElseIf RedValue < 5 AndAlso GreenValue < 5 AndAlso BlueValue < 5 Then
Msgbox("Pixel is of a black color...")
Else
Msgbox("Pixel is not white or black ...")
End If
Next
Next
Call UnlockBitmap(bmp) 'UNLOCKING BITMAP
picViewer1.Image = (bmp)
picViewer1.Refresh()
End Sub
Private Sub LockBitmap(ByVal bmp As Bitmap)
Dim bounds As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
bmpdata = bmp.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format24bppRgb)
g_RowSizeBytes = bmpdata.Stride
Dim total_size As Integer = bmpdata.Stride * bmpdata.Height
ReDim rgbValues(total_size)
Marshal.Copy(bmpdata.Scan0, rgbValues, 0, total_size)
End Sub
Private Sub UnlockBitmap(ByVal bmp As Bitmap)
Dim total_size As Integer = bmpdata.Stride * bmpdata.Height
Marshal.Copy(rgbValues, 0, bmpdata.Scan0, total_size)
bmp.UnlockBits(bmpdata)
rgbValues = Nothing
bmpdata = Nothing
End Sub