|
本帖最后由 hlzxcjx 于 2024-7-16 21:26 编辑
请问有没有好用的函数检测JPG或BMP的颜色?用函数DllCall($ghGDIPDll, 'uint', 'GdipBitmapGetPixel', 'ptr', $hImage, 'int', $iX, 'int', $iY, 'ptr*', 0)检测颜色,当检测的图片达一定量的时候就会出现错误,检测不出来!
下面的源码,当检测图片数达25个时,就出现错误:
#include <gdiplus.au3>
For $i = 2 To 30
FileCopy("1.jpg", $i & ".jpg")
Next
_GDIPlus_Startup()
For $k = 1 To 30
$hBitmap = _GDIPlus_BitmapCreateFromFile($k & ".jpg")
$aRet = _GDIPlus_ImageGetPixelFormat($hBitmap)
$h = _GDIPlus_ImageGetHeight($hBitmap)
$w = _GDIPlus_ImageGetWidth($hBitmap)
For $j = 0 To 100
For $i = 0 To $w - 1
$colour = _myBitmapGetPixel($hBitmap, $i, $j)
$colour2 = Dec(StringTrimLeft($colour, 4))
If $colour2 <> 16777215 Then
MsgBox(0, "颜色值=" & $colour & "--" & $colour2, "检测颜色出错!" & "第" & $k & "个图片,第" & $j & "行 第" & $i & "列")
EndIf
Next
ToolTip("第" & $k & "个图片,第" & $j & "行 第" & $i & "列")
Next
Next
MsgBox(0, 0, "end 第" & $k & "个图片,第" & $j & "行 第" & $i & "列")
_GDIPlus_ImageDispose($hBitmap)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()
Func _myBitmapCreate($iWidth, $iHeight, $iFormat = $GDIP_PXF24RGB);创建位图方式1, 此方法效率最高, 同时与Gdiplus兼容
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", $iFormat, "ptr", 0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[6]
EndFunc ;==>_myBitmapCreate
Func _myBitmapCreate2($iWidth, $iHeight, $iFormat = $GDIP_PXF32RGB);备忘: 我在2009年采用的WinApi方式创建位图方式, 只支持1,32 Bpp
Local $hRet, $hBitmap
Switch $iFormat
Case $GDIP_PXF01INDEXED
$iFormat = 1
Case Else
$iFormat = 32
EndSwitch
$hRet = _WinAPI_CreateBitmap($iWidth, $iHeight, 1, $iFormat)
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hRet)
_WinAPI_DeleteObject($hRet)
Return $hBitmap
EndFunc ;==>_myBitmapCreate2
Func _myBitmapSetPixel($hImage, $iX, $iY, $iArgb)
DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hImage, "int", $iX, "int", $iY, "dword", $iArgb)
If @error Then Return SetError(@error, @extended, 0)
EndFunc ;==>_myBitmapSetPixel
Func _myBitmapGetPixel($hImage, $iX, $iY)
Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipBitmapGetPixel', 'ptr', $hImage, 'int', $iX, 'int', $iY, 'ptr*', 0)
If @error Then
Return SetError(@error, @extended, 0)
Else
Return $aResult[4]
EndIf
EndFunc ;==>_myBitmapGetPixel
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|