myspacee Posted February 17, 2010 Share Posted February 17, 2010 Hello to all, use GDI to convert an image to another (png -> jpg) : #include <GDIPlus.au3> _Main() Func _Main() Local $hBitmap, $hImage, $sCLSID, $tData, $tParams ; Initialize GDI+ library _GDIPlus_Startup () ; Load image $hImage = _GDIPlus_ImageLoadFromFile ("01.png") ; Get JPEG encoder CLSID $sCLSID = _GDIPlus_EncodersGetCLSID ("JPG") ; Save image with rotation _GDIPlus_ImageSaveToFileEx ($hImage, "01.jpg", $sCLSID, DllStructGetPtr($tParams)) ; Shut down GDI+ library _GDIPlus_ShutDown () EndFunc ;==>_Main Read about _GDIPlus_GraphicsDrawImage that allow to draw an Image object, and think to use to resize obtained .jpg. But can't understand how use it ... Anyone can help me in this GDI convert&resing thing ? Thank you for your time, m. Link to comment Share on other sites More sharing options...
myspacee Posted February 17, 2010 Author Share Posted February 17, 2010 some step done, but not final, don't understand use of _GDIPlus_GraphicsDrawImageRectRect for : $iSrcX The X coordinate of the upper left corner of the source image $iSrcY The Y coordinate of the upper left corner of the source image update code: expandcollapse popup#include <GDIPlus.au3> global $my_Width = 500, $my_Height = 500 dim $local_file = "01.png" _Main() Func _Main() Local $hBitmap, $hImage, $sCLSID, $tData, $tParams ; Initialize GDI+ library _GDIPlus_Startup () ; Load image $hImage = _GDIPlus_ImageLoadFromFile ($local_file) ; Get JPEG encoder CLSID $sCLSID = _GDIPlus_EncodersGetCLSID ("JPG") ; Save image with rotation _GDIPlus_ImageSaveToFileEx ($hImage, "01.jpg", $sCLSID, DllStructGetPtr($tParams)) ; Shut down GDI+ library _GDIPlus_ShutDown () _resizeME($my_Width, $my_Height) EndFunc ;==>_Main Func _resizeME($my_Width, $my_Height) local $hBMP ;Start up GDIPlus _GDIPlus_Startup () ;Create canvas to put the resized image onto ;$hBMP = _CreateBitmap($oSize[1], $oSize[2]) $hBMP = _CreateBitmap($my_Width, $my_Height) $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ;Load an image file that you want to resize $hImage2 = _GDIPlus_ImageLoadFromFile("01.jpg") $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1) ;Put 2nd image onto the canvas at the desired size _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage2, 0, 0, 1000, 1000, 0, 0, $my_Width, $my_Height) ;===================================== ERROR HERE ============^^^^==^^^^============================== ;The encoder to use for the output image $CLSID = _GDIPlus_EncodersGetCLSID("JPG") ;Save the new resized image to a file ;~ _GDIPlus_ImageSaveToFileEx($hImage1, '"' & $sPath & "cool." & '"' & StringLower($Ext), $CLSID) _GDIPlus_ImageSaveToFileEx($hImage1,"_01.jpg", $CLSID) ;Clean up resources _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_DeleteObject($hBMP) ;Shut down GDIPlus _GDIPlus_Shutdown() EndFunc ;==>_Main Func _CreateBitmap($iW, $iH) Local $hWnd, $hDDC, $hCDC, $hBMP $hWnd = _WinAPI_GetDesktopWindow() $hDDC = _WinAPI_GetDC($hWnd) $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDDC) _WinAPI_DeleteDC($hCDC) Return $hBMP EndFunc ;==>_CreateBitmap anyone correct me please ? m. 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