本文介绍了元帅不能比吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我尽力比较并替换2个位图图像中白色的不同像素
但我得到了元帅的错误声明,以进行比较
任何解决方案可以帮助我进行比较和更换吗?
需要帮助!!!
最好的问候,
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
Function
推荐答案
这篇关于元帅不能比吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!