批量图片分割,文件大,数量多时会出错,释放资源也不行
本帖最后由 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
_GDIPlus_Startup()
For $i = 1 To 500
....
Next
_GDIPlus_ImageDispose($hClone)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown() haijie1223 发表于 2024-10-30 22:10
这样不行呢。我原来就是这样写的,后来考虑可能没释放资源就改为每个图片都释放一次,结果还是不行。测试没出错的可能电脑配置较高,改个十几M的或分辨率大的图片可能就会出错。 hlzxcjx 发表于 2024-10-31 07:24
这样不行呢。我原来就是这样写的,后来考虑可能没释放资源就改为每个图片都释放一次,结果还是不行。测试 ...
没遇到,我这里正常
页:
[1]