myspacee Posted April 18, 2008 Share Posted April 18, 2008 hello to all, is possible to resize image without external tool ? I've an image and i wanto to crop to another dimension... thank you for any help m. Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 18, 2008 Share Posted April 18, 2008 Hi, why automating this? Once done the pic is ready to use. May try Irfanview or you trying to write the functions itself? Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
myspacee Posted April 18, 2008 Author Share Posted April 18, 2008 Xenobiologist thank you for reply,make my snapshot tool and i want to add one feature. When snapshot a square area, auto resize it with given dimension (70x70, 150x150, etc)This feauture can help me to update job www site, that have a lot of limit for image upload (dimension, kb, etc)Hope in Autoit power !? ( or autoinstall program that can do this operation (imagemagick, infranview....))Thank again for any info,m. Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 18, 2008 Share Posted April 18, 2008 Hi, try this: expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> _screenShotActiveWindow(@DesktopDir & "\window_screenshot.jpg") Global $oSize[3] $oSize[1] = 500 $oSize[2] = 500 $iPath = FileOpenDialog("Choose image", @DesktopDir & "\", "Images (*.jpg)", 1) $Ext = "jpg" $sPath = "C:\" ;Start up GDIPlus _GDIPlus_Startup () ;Create canvas to put the resized image onto $hBMP = _CreateBitmap($oSize[1], $oSize[2]) $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ;Load an image file that you want to resize $hImage2 = _GDIPlus_ImageLoadFromFile($iPath) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1) ;Put 2nd image onto the canvas at the desired size _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $oSize[1], $oSize[2]) ;The encoder to use for the output image $CLSID = _GDIPlus_EncodersGetCLSID(StringUpper($Ext)) ;Save the new image to a file ;~ _GDIPlus_ImageSaveToFileEx($hImage1, '"' & $sPath & "cool." & '"' & StringLower($Ext), $CLSID) _GDIPlus_ImageSaveToFileEx($hImage1,@DesktopDir & '\small.jpg', $CLSID) ;Clean up resources _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_DeleteObject($hBMP) ;Shut down GDIPlus _GDIPlus_Shutdown() 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 Func _screenShotActiveWindow($path) Local $opt = AutoItSetOption("WinTitleMatchMode", 4) _ScreenCapture_CaptureWnd($path, WinGetHandle(WinGetTitle('active'))) AutoItSetOption("WinTitleMatchMode", $opt) EndFunc ;==>_screenShotActiveWindow Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
myspacee Posted April 19, 2008 Author Share Posted April 19, 2008 thank you very much, some little adjusments but is perfect for my use m. Link to comment Share on other sites More sharing options...
Achilles Posted April 19, 2008 Share Posted April 19, 2008 Thanks from me too... This will be useful for something I had been trying to do. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
rasim Posted April 20, 2008 Share Posted April 20, 2008 XenobiologistHi! What the function _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $oSize[1], $oSize[2])? I got error when i run your example. Autoit version 3.2.10.0 Link to comment Share on other sites More sharing options...
myspacee Posted April 20, 2008 Author Share Posted April 20, 2008 rasim, 'some little adjusments ' needed missing dest x y , and some other pars, watch guide to complete func. m. Link to comment Share on other sites More sharing options...
smashly Posted April 20, 2008 Share Posted April 20, 2008 (edited) Hi, try this: expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> _screenShotActiveWindow(@DesktopDir & "\window_screenshot.jpg") Global $oSize[3] $oSize[1] = 500 $oSize[2] = 500 $iPath = FileOpenDialog("Choose image", @DesktopDir & "\", "Images (*.jpg)", 1) $Ext = "jpg" $sPath = "C:\" ;Start up GDIPlus _GDIPlus_Startup () ;Create canvas to put the resized image onto $hBMP = _CreateBitmap($oSize[1], $oSize[2]) $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ;Load an image file that you want to resize $hImage2 = _GDIPlus_ImageLoadFromFile($iPath) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1) ;Put 2nd image onto the canvas at the desired size _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $oSize[1], $oSize[2]) ;The encoder to use for the output image $CLSID = _GDIPlus_EncodersGetCLSID(StringUpper($Ext)) ;Save the new image to a file ;~ _GDIPlus_ImageSaveToFileEx($hImage1, '"' & $sPath & "cool." & '"' & StringLower($Ext), $CLSID) _GDIPlus_ImageSaveToFileEx($hImage1,@DesktopDir & '\small.jpg', $CLSID) ;Clean up resources _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_DeleteObject($hBMP) ;Shut down GDIPlus _GDIPlus_Shutdown() 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 Func _screenShotActiveWindow($path) Local $opt = AutoItSetOption("WinTitleMatchMode", 4) _ScreenCapture_CaptureWnd($path, WinGetHandle(WinGetTitle('active'))) AutoItSetOption("WinTitleMatchMode", $opt) EndFunc;==>_screenShotActiveWindow MegaNice, some of that code looks familiar to me.. Cheers Edited April 20, 2008 by smashly Link to comment Share on other sites More sharing options...
rasim Posted April 20, 2008 Share Posted April 20, 2008 rasim,'some little adjusments ' neededmissing dest x y , and some other pars, watch guide to complete func.m.I don`t understand. Link to comment Share on other sites More sharing options...
smashly Posted April 20, 2008 Share Posted April 20, 2008 (edited) Xenobiologist Hi! What the function _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $oSize[1], $oSize[2])? I got error when i run your example. Autoit version 3.2.10.0The function wasn't added till v3.2.11.0 (beta).. Here's the function , just add it to the example that Xenobiologist gave; =================================== ; Name...........: _GDIPlus_GraphicsDrawImageRect ; Description ...: Draws an image at a specified location ; Syntax.........: _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH ) ; Parameters ....: $hGraphics - Handle to a Graphics object ; $hImage - Handle to an Image object ; $iX - The X coordinate of the upper left corner of the rendered image ; $iY - The Y coordinate of the upper left corner of the rendered image ; $iW - Specifies the width of the destination rectangle at which to draw the image ; $iH - Specifies the height of the destination rectangle at which to draw the image ; Return values .: Success - True ; Failure - False ; Author ........: smashly ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; @@MsdnLink@@ GdipDrawImageRectI ; Example .......; Yes ; ================================================================ Func _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH) Local $aResult $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iX, "int", $iY, "int", $iW, "int", $iH) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_GraphicsDrawImageRect Cheers Edited April 20, 2008 by smashly 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