Question

I have an image and rotate it with both MS Paint and GDI. I want to show that the rotated image from both methods are the same.

Here is the code I have to rotate image with GDI

#include <GDIPlus.au3>

_GDIPlus_Startup()

$hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Picture.gif")
$hGraphic1 = _GDIPlus_ImageGetGraphicsContext($hImage1)
$hImage2 = _GDIPlus_BitmapCreateFromGraphics(_GDIPlus_ImageGetWidth($hImage1), _GDIPlus_ImageGetHeight($hImage1), $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hImage2)

$matrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixRotate($matrix,90)
_GDIPlus_GraphicsSetTransform($hGraphic2, $matrix)
_GDIPlus_GraphicsDrawImage($hGraphic2, $hImage1, 0, -590)

_GDIPlus_ImageSaveToFile($hImage2, @ScriptDir & "\out.gif")

_GDIPlus_MatrixDispose($matrix)
_GDIPlus_GraphicsDispose($hGraphic1)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)

 _GDIPlus_ShutDown ()

Then I used this code to compare 2 images:

$bm1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Picture1.gif")
$bm2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\out.gif")

if ComparePicture($bm1, $bm2) == True Then
   MsgBox(0, "Test result", "Same image!")
Else
   MsgBox(0, "Test result", "Different image!")
EndIf

_GDIPlus_ImageDispose($bm1)
_GDIPlus_ImageDispose($bm2)
_GDIPlus_Shutdown()

Func ComparePicture($bm1, $bm2)

$Bm1W = _GDIPlus_ImageGetWidth($bm1)
$Bm1H = _GDIPlus_ImageGetHeight($bm1)
$BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF08INDEXED )
$Stride = DllStructGetData($BitmapData1, "Stride")
$Scan0 = DllStructGetData($BitmapData1, "Scan0")

$ptr1 = $Scan0
$size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4


$Bm2W = _GDIPlus_ImageGetWidth($bm2)
$Bm2H = _GDIPlus_ImageGetHeight($bm2)
$BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF08INDEXED)
$Stride = DllStructGetData($BitmapData2, "Stride")
$Scan0 = DllStructGetData($BitmapData2, "Scan0")

$ptr2 = $Scan0
$size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4

$smallest = $size1
If $size2 < $smallest Then $smallest = $size2
$call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)



_GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
_GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)

Return ($call[0]=0)
EndFunc  

I tried changing the file type, color depth, etc. but I could not get the code to show that they are the same. When I do not rotate the picture i.e

_GDIPlus_MatrixRotate($matrix,0)

then it recognize the same image. When I rotate right 90, it doesn't. Does anyone knows what might be going on?

Thanks


For reference, this question has also been asked on the AutoIt forums here.

Was it helpful?

Solution

I think $GDIP_PXF08INDEXED is modifying the images differently. Try it without setting it and it should work.

Furthermore, you can use this code to flip the image:

$hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Picture1.gif")
_GDIPlus_ImageRotateFlip($hImage1, 1) ;90°

_GDIPlus_ImageSaveToFile($hImage1, @ScriptDir & "\out.gif")

_GDIPlus_ImageDispose($hImage1)

Br,

UEZ

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top