qwert Posted March 13, 2017 Posted March 13, 2017 I'm scaling (down) a JPG and want to preserve the greatest possible quality level that's available in the original image. This means—I think—that I need to write the downsized image with Quality = 100%. (I'll mention that the original image is from a camera that uses a default quality setting of 90%, so it already has some level of compression.) msdn explains it this way: Quote “To specify the compression level when you save a JPEG image, initialize an EncoderParameters object and pass the address of that object to the Save method of the Image class.” I've looked at the following code from the GDI+ UDF and it seems to be passing the quality level from the original image ($sEncoder). So, if I don't intervene, it seems it will be requesting a JPG quality of 90%, which would further compress the image. Indeed, that's what seems to happen, because my written result is always smaller than what is produced by a 3rd party package that has quality set to 100% ; #FUNCTION# ==================================================================================================================== ; Author ........: Paul Campbell (PaulIA) ; Modified.......: Gary Frost ; =============================================================================================================================== Func _GDIPlus_ImageSaveToFile($hImage, $sFileName) Local $sExt = __GDIPlus_ExtractFileExt($sFileName) Local $sCLSID = _GDIPlus_EncodersGetCLSID($sExt) If $sCLSID = "" Then Return SetError(-1, 0, False) Local $bRet = _GDIPlus_ImageSaveToFileEx($hImage, $sFileName, $sCLSID, 0) Return SetError(@error, @extended, $bRet) EndFunc ;==>_GDIPlus_ImageSaveToFile ; #FUNCTION# ==================================================================================================================== ; Author ........: Paul Campbell (PaulIA) ; Modified.......: Gary Frost, jpm ; =============================================================================================================================== Func _GDIPlus_ImageSaveToFileEx($hImage, $sFileName, $sEncoder, $tParams = 0) Local $tGUID = _WinAPI_GUIDFromString($sEncoder) Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipSaveImageToFile", "handle", $hImage, "wstr", $sFileName, "struct*", $tGUID, "struct*", $tParams) If @error Then Return SetError(@error, @extended, False) If $aResult[0] Then Return SetError(10, $aResult[0], False) Return True EndFunc ;==>_GDIPlus_ImageSaveToFileEx All this is a good bit beyond my experience level with GDI+ and I will appreciate hearing from someone with knowledge of these considerations. Thanks in advance.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now