Hi , all i try to compare and replace different pixel between 2 bitmap images with white color
but i got Error statement with marshal to compare
Any solution Help me compare and replace it ?
need Help!!!
Best Regard,
Public Function ComparePixel(ByVal input As Bitmap) As Bitmap
tempref = (System.Drawing.Image.FromFile("C:\refBG\img0.bmp"))
Dim CloneRect As New RectangleF(0, 0, input.Width, input.Height)
Dim ClonedBitmap = input.Clone(CloneRect, PixelFormat.DontCare)
Dim x As Integer
Dim y As Integer
Dim c1, c2 As Color
Dim bmd As BitmapData = ClonedBitmap.LockBits(New Rectangle(0, 0, input.Width, input.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, ClonedBitmap.PixelFormat)
Dim refbmd As BitmapData = tempref.LockBits(New Rectangle(0, 0, input.Width, input.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, tempref.PixelFormat)
Dim index, refindex As Integer
For y = 0 To input.Height
For x = 0 To input.Width
index = y * bmd.Stride + x * 4
refindex = y * refbmd.Stride + x * 4
If (Color.FromArgb(Marshal.ReadByte(bmd.Scan0, index + 2), Marshal.ReadByte(bmd.Scan0, index + 1), Marshal.ReadByte(bmd.Scan0, index)).ToArgb()).Equals(Color.FromArgb(Marshal.ReadByte(refbmd.Scan0, index + 2), Marshal.ReadByte(refbmd.Scan0, index + 1), Marshal.ReadByte(refbmd.Scan0, index))) Then
Marshal.WriteByte(bmd.Scan0, index + 2, 255)
Marshal.WriteByte(bmd.Scan0, index + 1, 255)
Marshal.WriteByte(bmd.Scan0, index, 255)
End If
Next
Next
ClonedBitmap.UnlockBits(bmd)
tempref.UnlockBits(refbmd)
Return ClonedBitmap
End
Function