devilyn Posted March 25, 2009 Share Posted March 25, 2009 All, thank you for reading this post. i would like to read an image file and save it with my own DPI value. bellow is what i have up to now. #include <GDIPlus.au3> Opt('MustDeclareVars', 1) ;Global $iMemo _Main() Func _Main() Local $hBitmap, $hImage ,$ImageHandle,$Status ; Initialize GDI+ library _GDIPlus_Startup() ; Capture bitmap $hImage = _GDIPlus_BitmapCreateFromFile (@ScriptDir&"\new.jpg") ; Show horizontal resolution in DPI (dots per inch) of image ConsoleWrite( _GDIPlus_ImageGetHorizontalResolution($hImage)&@CRLF); only to console Local $Ext = _GDIPlus_EncodersGetCLSID("JPG") $Status = _GDIPlus_ImageSaveToFileEx($hImage,@ScriptDir&"\converted.JPG", $Ext, 0) MsgBox(0,$hImage,$Status) ; Clean up resources _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>_Main Thanks in advance Link to comment Share on other sites More sharing options...
devilyn Posted March 25, 2009 Author Share Posted March 25, 2009 while searching in google i found out that i need to call "GdipBitmapSetResolution" from "GDIPlus.dll" now i wrote a dll call for this function but I'm not sure it works and if it works i cannot figure out how to save it as a new file. $aResult = DllCall("GDIPlus.dll", "int", "GdipBitmapSetResolution", "hwnd", $hImage, "int*", 72 ,"int*",72) Link to comment Share on other sites More sharing options...
rover Posted March 25, 2009 Share Posted March 25, 2009 Hi Lior, try this expandcollapse popup#include <GDIPlus.au3> Opt('MustDeclareVars', 1) ;Global $iMemo _Main() Func _Main() Local $hBitmap, $hImage ,$ImageHandle,$Status ; Initialize GDI+ library _GDIPlus_Startup() ; Capture bitmap $hImage = _GDIPlus_BitmapCreateFromFile (@ScriptDir&"\new.jpg") ; Show horizontal resolution in DPI (dots per inch) of image ConsoleWrite("+ " & _GDIPlus_ImageGetHorizontalResolution($hImage) & " PPI" &@CRLF); only to console Local $aResult = _GDIPlus_BitmapSetResolution($hImage, 72, 72) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aResult = ' & $aResult & @crlf & '>Error code: ' & @error & @crlf) Local $Ext = _GDIPlus_EncodersGetCLSID("JPG") $Status = _GDIPlus_ImageSaveToFileEx($hImage,@ScriptDir&"\converted.JPG", $Ext, 0) ;MsgBox(0,$hImage,$Status) $hImage = _GDIPlus_BitmapCreateFromFile (@ScriptDir&"\converted.JPG") ; Show horizontal resolution in DPI (dots per inch) of image ConsoleWrite("+ " & _GDIPlus_ImageGetHorizontalResolution($hImage) & " PPI" &@CRLF); only to console ; Clean up resources _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>_Main Func _GDIPlus_BitmapSetResolution($hImage, $iPPIHoriz, $iPPIVert) ;Author(s): rover, Lior Berezinski, et al. If ($hImage = -1) Or (Not $hImage) Then Return SetError(4, 0, 0) Local $aResult, $iError = 0 $aResult = DllCall($ghGDIPDll, "int", "GdipBitmapSetResolution", _ "hwnd", $hImage, "float", $iPPIHoriz ,"float",$iPPIVert) $iError = @error If @error Or IsArray($aResult) = 0 Then Return SetError($iError, 0, 0) Return SetError($iError, 0, $aResult[0]) EndFunc ;==>_GDIPlus_BitmapSetResolution I see fascists... Link to comment Share on other sites More sharing options...
devilyn Posted March 27, 2009 Author Share Posted March 27, 2009 Hi Lior, try this expandcollapse popup#include <GDIPlus.au3> Opt('MustDeclareVars', 1) ;Global $iMemo _Main() Func _Main() Local $hBitmap, $hImage ,$ImageHandle,$Status ; Initialize GDI+ library _GDIPlus_Startup() ; Capture bitmap $hImage = _GDIPlus_BitmapCreateFromFile (@ScriptDir&"\new.jpg") ; Show horizontal resolution in DPI (dots per inch) of image ConsoleWrite("+ " & _GDIPlus_ImageGetHorizontalResolution($hImage) & " PPI" &@CRLF); only to console Local $aResult = _GDIPlus_BitmapSetResolution($hImage, 72, 72) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aResult = ' & $aResult & @crlf & '>Error code: ' & @error & @crlf) Local $Ext = _GDIPlus_EncodersGetCLSID("JPG") $Status = _GDIPlus_ImageSaveToFileEx($hImage,@ScriptDir&"\converted.JPG", $Ext, 0) ;MsgBox(0,$hImage,$Status) $hImage = _GDIPlus_BitmapCreateFromFile (@ScriptDir&"\converted.JPG") ; Show horizontal resolution in DPI (dots per inch) of image ConsoleWrite("+ " & _GDIPlus_ImageGetHorizontalResolution($hImage) & " PPI" &@CRLF); only to console ; Clean up resources _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() EndFunc ;==>_Main Func _GDIPlus_BitmapSetResolution($hImage, $iPPIHoriz, $iPPIVert) ;Author(s): rover, Lior Berezinski, et al. If ($hImage = -1) Or (Not $hImage) Then Return SetError(4, 0, 0) Local $aResult, $iError = 0 $aResult = DllCall($ghGDIPDll, "int", "GdipBitmapSetResolution", _ "hwnd", $hImage, "float", $iPPIHoriz ,"float",$iPPIVert) $iError = @error If @error Or IsArray($aResult) = 0 Then Return SetError($iError, 0, 0) Return SetError($iError, 0, $aResult[0]) EndFunc ;==>_GDIPlus_BitmapSetResolution it runs but it does not change the DPI. console log: + 72 DPI @@ Debug(28) : $aResult = 0 >Error code: 0 + 72 DPI thanks for you help Link to comment Share on other sites More sharing options...
rover Posted March 28, 2009 Share Posted March 28, 2009 it runs but it does not change the DPI.console log:+ 72 DPI@@ Debug(28) : $aResult = 0>Error code: 0+ 72 DPIthanks for you helpLiorthe function works, I'm not so sure its done anything to the image, other than change that value I'm not familiar with the usage of this function, isn't resizing involved for this to do anything?_GDIPlus_BitmapSetResolution returns 0 on successI used a screen cap jpg from a help file example: GDIPlus_ImageSaveToFile ($hImage, @MyDocumentsDir & "\GDIPlus_Image.jpg")the saved files resolution was changed from 96 to 72but when tested with other non-GDI+ saved jpegs, the bitmap was not saved with a new resolution, a consolewrite of ImageGetHorizontalResolution after BitmapSetResolution shows theimage resolution was changed but wasn't saved in the jpg.saving as bmp or png works but not with jpg.not much of anything on MSDN or other sites that I could find on this.Good luck I see fascists... Link to comment Share on other sites More sharing options...
devilyn Posted March 30, 2009 Author Share Posted March 30, 2009 Liorthe function works, I'm not so sure its done anything to the image, other than change that value I'm not familiar with the usage of this function, isn't resizing involved for this to do anything?_GDIPlus_BitmapSetResolution returns 0 on successI used a screen cap jpg from a help file example: GDIPlus_ImageSaveToFile ($hImage, @MyDocumentsDir & "\GDIPlus_Image.jpg")the saved files resolution was changed from 96 to 72but when tested with other non-GDI+ saved jpegs, the bitmap was not saved with a new resolution, a consolewrite of ImageGetHorizontalResolution after BitmapSetResolution shows theimage resolution was changed but wasn't saved in the jpg.saving as bmp or png works but not with jpg.not much of anything on MSDN or other sites that I could find on this.Good luckSOLVEDThanks it works with PNG. Link to comment Share on other sites More sharing options...
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