Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,

VB
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
Posted
Comments
Kschuler 22-Sep-10 14:15pm    
what's the error message.

1 solution

Hi , Kschuler

Error msg is

AccessViolationException was unhandled

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900