AutoIT 脚本 - 将画图的旋转图像与 GDI 的旋转图像进行比较



我有一个图像,并用MS Paint和GDI旋转它。我想展示两种方法的旋转图像是相同的。

这是我必须用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 ()

然后我用这个代码来比较两个图像:

$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  

我尝试更改文件类型、颜色深度等,但无法获得显示它们相同的代码。当我不旋转图片时,即

_GDIPlus_MatrixRotate($matrix,0)

则它识别出相同的图像。当我向右旋转90度时,它不会。有人知道可能发生了什么吗?

感谢


作为参考,这个问题也在这里的AutoIt论坛上提出过。

我认为$GDIP_PXF08INDEXED正在以不同的方式修改图像。在不设置的情况下尝试它,它应该会起作用。

此外,您可以使用此代码翻转图像:

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

Br,

UEZ

相关内容

  • 没有找到相关文章

最新更新