本帖最后由 afan 于 2010-8-20 21:13 编辑 #include <GDIPlus.au3>
_Pic2jpg('a.BMP', 'b.jpg', 60) ;质量60
Func _Pic2jpg($sFileName, $oFileName, $iQuality = 100)
;Afan提示:转换任意格式图片为jpg格式,可设置$iQuality质量参数,0-100
;成功返回True;失败返回False,并设置@Error = 1
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($sFileName)
If $iQuality < 0 Then $iQuality = 0
If $iQuality > 100 Then $iQuality = 100
Local $giQuality = $iQuality, $pParams
Local $tParams = _GDIPlus_ParamInit(1)
Local $tData = DllStructCreate('int Quality')
DllStructSetData($tData, 'Quality', $giQuality)
_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData))
If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams)
Local $CLSID = _GDIPlus_EncodersGetCLSID('JPG')
Local $save = _GDIPlus_ImageSaveToFileEx($hImage, $oFileName, $CLSID, $pParams)
_GDIPlus_Shutdown()
If $save = False Then Return SetError(1, 0, False)
Return True
EndFunc ;==>_Pic2jpg
|