Image Processing:

  • Thread starter Thread starter TEST
  • Start date Start date
T

TEST

First off I know about the managed bitmap.getpixel/setpixel.

Now,

I am attempting to run unmanaged GDI code to compare 2 bitmaps and re-write
a 3rd bitmap with the changes. Problem is I get the same result for every
pixel using getpixel call. Getpixel does not return CLR_INVALID but returns
the same integer every time. Can someone point me in the right direction.

Private Function DrawDiff1(ByVal BitmapA As Bitmap, ByVal BitmapB As
Bitmap, ByVal PixelHigh As Integer, ByVal PixelLow As Integer) As Bitmap

Dim BitmapC As Bitmap = BitmapA.Clone
Dim obj_DCA As Graphics = Graphics.FromImage(BitmapA)
Dim obj_DCB As Graphics = Graphics.FromImage(BitmapB)
Dim obj_DCC As Graphics = Graphics.FromImage(BitmapC)

Dim obj_HDCA As IntPtr = obj_DCA.GetHdc
Dim obj_HDCB As IntPtr = obj_DCB.GetHdc
Dim obj_HDCC As IntPtr = obj_DCC.GetHdc

Dim x As Integer = 0, y As Integer = 0

For y = 0 To BitmapA.Height - 1 Step 1
For x = 0 To BitmapA.Width - 1 Step 1

Dim int_PixelA As Integer = GetPixel(obj_HDCA, x, y)
Dim int_PixelB As Integer = GetPixel(obj_HDCB, x, y)


If int_PixelA = CLR_INVALID Or int_PixelB = CLR_INVALID Then
Stop

'Dim obj_PixelColorA As Color = BitmapA.GetPixel(x, y)
'Dim int_PixelColorA As Integer = obj_PixelColorA.ToArgb
'Dim obj_PixelColorB As Color = BitmapB.GetPixel(x, y)
'Dim int_PixelColorB As Integer = obj_PixelColorB.ToArgb

'If obj_ColorA.Red <> obj_ColorB.Red Then Stop
'If obj_ColorA.Blue <> obj_ColorB.Blue Then Stop
'If obj_ColorA.Green <> obj_ColorB.Green Then Stop

If int_PixelA <> int_PixelB Then Stop
SetPixel(obj_HDCC, x, y, int_PixelA)
Next
Next
obj_DCA.ReleaseHdc(obj_HDCA)
obj_DCB.ReleaseHdc(obj_HDCB)
obj_DCC.ReleaseHdc(obj_HDCC)


Dim int_Return As Integer = 0
int_Return = ReleaseDC(0, obj_HDCA)
'Debug.WriteLine("ReleaseDC: " & int_Return)
int_Return = ReleaseDC(0, obj_HDCB)
'Debug.WriteLine("ReleaseDC: " & int_Return)
int_Return = ReleaseDC(0, obj_HDCC)
'Debug.WriteLine("ReleaseDC: " & int_Return)

Return BitmapC
End Function
 
Dim int_PixelA As Integer = GetPixel(obj_HDCA, x, y)

What's your declaration of GetPixel? Which OS do you use? 32/64 Bit
Version? Args should be IntPtr, IntPtr and return value = Integer

Probably not the problem, but calling the managed and unmanaged version
of ReleaseHDC is only done in this example? (accidently not commentet
out I guess)


Armin
 
Back
Top