Hello all I am attempting to convert BMP file to JPEG to reduce their size, below is the code I am currently trying to use.
AutoIt
_GDIPlus_Startup() $hImage = _GDIPlus_BitmapCreateFromFile($snapfile) ;$snapfile is the origin BMP file $ret = Bitmap2BinaryString($himage, 60) _GDIPlus_BitmapDispose($hImage) _WinAPI_DeleteObject($hImage) _GDIPlus_Shutdown() FileWrite("ss.jpg", binary($ret)) Func Bitmap2BinaryString($hBitmap, $JPEG_Quality = 90) ;code by Andreik, modified by UEZ Local $declared = True If Not $ghGDIPDll Then _GDIPlus_Startup() $declared = False EndIf Local $STREAM = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", 1, "ptr*", 0) $STREAM = $STREAM[3] Local $JPG_ENCODER = _GDIPlus_EncodersGetCLSID("JPG") Local $TAG_ENCODER = _WinAPI_GUIDFromString($JPG_ENCODER) Local $PTR_ENCODER = DllStructGetPtr($TAG_ENCODER) Local $tParams = _GDIPlus_ParamInit (1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $JPEG_Quality) Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $STREAM, "ptr", $PTR_ENCODER, "ptr", $pParams) $tData = 0 $tParams = 0 Local $MEMORY = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $STREAM, "ptr*", 0) $MEMORY = $MEMORY[2] Local $MEM_SIZE = _MemGlobalSize($MEMORY) Local $MEM_PTR = _MemGlobalLock($MEMORY) Local $DATA_STRUCT = DllStructCreate("byte[" & $MEM_SIZE & "]", $MEM_PTR) Local $DATA = DllStructGetData($DATA_STRUCT, 1) Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $STREAM, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) _MemGlobalFree($MEMORY) If Not $declared Then _GDIPlus_Shutdown() Return $DATA EndFunc
Every time I try this code the resulting jpeg file is only 4bytes in size, can anyone see what what might be causing this, or what I might be doing wrong?