本帖最后由 hlzxcjx 于 2024-10-30 18:54 编辑
请下载附件测试,批量切割图片,具体到哪个文件出错,与电脑配置有关。如没有出错,可替换一个几M或十几M的图片,数量可更改。但总会出错,切割每个图片时用_GDIPlus_ImageDispose,_GDIPlus_Shutdown()释放资源也不行!有没有解决办法呢?
;插入代码框不能显示斜杠,代码有误,下面的纯文本正确,附件正确!#include <GDIPlus.au3>
$Width = 5
$Height = 3
For $i = 1 To 499
FileCopy("1" & $i & ".jpg", "1" & $i + 1 & ".jpg")
Next
DirCreate("2")
For $i = 1 To 500
$Bmpfile = "1" & $i & ".jpg"
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($Bmpfile)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$z = 0
For $y = 1 To $Height
For $x = 1 To $Width
$hClone = _GDIPlus_BitmapCloneArea($hImage, ($x - 1) * ($iX / $Width), ($y - 1) * ($iY / $Height), $iX / $Width, $iY / $Height, $GDIP_PXF24RGB)
_GDIPlus_ImageSaveToFile($hClone, "2" & $i & "-" & $z + 1 & ".jpg")
ToolTip(($i - 1) * $Width * $Height + $z + 1 & " 2" & $i & "-" & $z + 1 & ".jpg")
If FileExists("2" & $i & "-" & $z + 1 & ".jpg") = 0 Then MsgBox(0, "出错!", ($i - 1) * $Width * $Height + $z + 1 & " 2" & $i & "-" & $z + 1 & ".jpg")
$z += 1
Next
Next
_GDIPlus_ImageDispose($hClone)
_GDIPlus_ImageDispose($hImage)
;_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()
Next
#include <GDIPlus.au3>
$Width = 5
$Height = 3
For $i = 1 To 499
FileCopy("1\" & $i & ".jpg", "1\" & $i + 1 & ".jpg")
Next
DirCreate("2\")
For $i = 1 To 500
$Bmpfile = "1\" & $i & ".jpg"
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($Bmpfile)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$z = 0
For $y = 1 To $Height
For $x = 1 To $Width
$hClone = _GDIPlus_BitmapCloneArea($hImage, ($x - 1) * ($iX / $Width), ($y - 1) * ($iY / $Height), $iX / $Width, $iY / $Height, $GDIP_PXF24RGB)
_GDIPlus_ImageSaveToFile($hClone, "2\" & $i & "-" & $z + 1 & ".jpg")
ToolTip(($i - 1) * $Width * $Height + $z + 1 & " 2\" & $i & "-" & $z + 1 & ".jpg")
If FileExists("2\" & $i & "-" & $z + 1 & ".jpg") = 0 Then MsgBox(0, "出错!", ($i - 1) * $Width * $Height + $z + 1 & " 2\" & $i & "-" & $z + 1 & ".jpg")
$z += 1
Next
Next
_GDIPlus_ImageDispose($hClone)
_GDIPlus_ImageDispose($hImage)
;_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()
Next
|