9月12018
Au3图片转灰度
$sFile = '111.jpg' ;需要处理的图片
$sFile_Gray = '1_去色.jpg' ;保存输出的图片
_GDIPlus_Startup()
_GDIPlus_ImageToGray($sFile, $sFile_Gray)
_GDIPlus_Shutdown()
Func _GDIPlus_ImageToGray($sFile, $sFile_Gray = '')
;=====将彩色转为灰度(去色),输出文件或灰度图像对象句柄
Local $hImage, $iW, $iH, $hGraphics, $tCOLORMATRIX, $pCOLORMATRIX, $FS
$hImage = _GDIPlus_ImageLoadFromFile($sFile) ;載入圖片
$iW = _GDIPlus_ImageGetWidth($hImage) ;获取图片 宽度
$iH = _GDIPlus_ImageGetHeight($hImage) ;获取图片 高度
$hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)
$hIA = _GDIPlus_ImageAttributesCreate()
$tCOLORMATRIX = _GDIPlus_ColorMatrixCreateGrayScale()
$pCOLORMATRIX = DllStructGetPtr($tCOLORMATRIX)
_GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, 1, $pCOLORMATRIX)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, 0, $iW, $iH, 0, 0, $iW, $iH, $hIA) ;顏色灰度處理
If $sFile_Gray <> '' Then
$FS = _GDIPlus_ImageSaveToFile($hImage, $sFile_Gray) ;保存图片
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_ImageDispose($hImage)
Return $FS
Else
Return $hImage
EndIf
EndFunc ;==>_GDIPlus_ImageToGray
</gdiplus.au3>```
主要用到 <gdiplus.au3><span style="color:#E53333;">_GDIPlus_GraphicsDrawImageRectRect</span> 函数,收藏做个记录备用</gdiplus.au3>
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!