Jump to content

Resize image without external tool


Recommended Posts

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

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

Hi,

try this:

#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

Hi,

try this:

#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

Nice, some of that code looks familiar to me..

Cheers

Edited by smashly
Link to comment
Share on other sites

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.0

The 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 by smashly
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...