Jump to content

Size of image


Go to solution Solved by wakillon,

Recommended Posts

I have been looking in the help file but cant find a function that will tell me the width/height in pixels of an image. Im working with GUIs using the GDI stuff but cant find anything that i can define a variable with a width/height of some random image.

Thanks in advance,

Maosn

Link to comment
Share on other sites

  • Solution

I have been looking in the help file but cant find a function that will tell me the width/height in pixels of an image. Im working with GUIs using the GDI stuff but cant find anything that i can define a variable with a width/height of some random image.

Thanks in advance,

Maosn

 

See help file for GDI functions.

#Include <GDIPlus.au3>
#Include <Array.au3>

_GDIPlus_Startup ()
$a = _ImageGetDimension ( 'D:\Bureau\pics\123456.jpg' )
_ArrayDisplay ( $a )
_GDIPlus_Shutdown ()

Func _ImageGetDimension ( $sPicPath )
    If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
    Local $hImage = _GDIPlus_ImageLoadFromFile ( $sPicPath )
    Local $aRet[2]
    $aRet[0] = _GDIPlus_ImageGetWidth ( $hImage )
    $aRet[1] = _GDIPlus_ImageGetHeight ( $hImage )
    _GDIPlus_ImageDispose ( $hImage )
    If $aRet[0] And $aRet[1] Then Return $aRet
EndFunc ;==> _ImageGetDimension ()

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

As you asked for GDI and not GDI+ here the GDI version:

#include <Array.au3>
#include <Screencapture.au3>

Global $hScreen = _ScreenCapture_Capture("", Random(0, 50, 1), Random(0, 50, 1), Random(100, 500, 1), Random(100, 500, 1))
Global $aDim = _WinAPI_BitmapGetDim($hScreen)
_ArrayDisplay($aDim)

Func _WinAPI_BitmapGetDim($hHBitmap)
    Local $tDim = DllStructCreate($tagBITMAP)
    DllCall("gdi32.dll", "int", "GetObject", "int", $hHBitmap, "int", DllStructGetSize($tDim), "struct*", $tDim)
    If @error Then Return SetError(1, 0, 0)
    Local $aDim[2] = [$tDim.bmWidth, $tDim.bmHeight]
    Return $aDim
EndFunc

Br,

UEZ ;)

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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

×
×
  • Create New...