Sign in to follow this  
Followers 0
d3mon

Can i have Width & Height of picture by FileOpenDialog ?

17 posts in this topic

Hello Everybody,

Can i have Width & Height of picture by FileOpenDialog ?

Thanks


No-life of autoit...what could be better ?LAST SCRIPTS WITH AUTO-IT : CLICK HERE

Share this post


Link to post
Share on other sites



OPen the image with GDIplus and use _GDIplus_ImageGetWidth / _GDIplus_ImageGetHeight.

OPen/Close:

_GDIplus_ImageLoadFromFile

_GDIplus_ImageDispose


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

OPen the image with GDIplus and use _GDIplus_ImageGetWidth / _GDIplus_ImageGetHeight.

OPen/Close:

_GDIplus_ImageLoadFromFile

_GDIplus_ImageDispose

I've just been trying to do just that and failed. My understanding of images and graphic objects is awful so this sort of thing could help me learn.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <staticconstants.au3>
#include <gdiplus.au3>
Const $SS_REALSIZEIMAGE = 0x800
#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 413, 298, 303, 219)
$Pic1 = GUICtrlCreatePic("", 48, 16, 100, 100, BitOR($SS_NOTIFY,$SS_REALSIZEIMAGE,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$sFileName = FileOpenDialog("pic","\","jpg(*.jpg)");tried bmp but no better
ConsoleWrite($sFileName & @CRLF)
$hImage = _GDIPlus_ImageLoadFromFile($sFileName);AutoIt crashes
ConsoleWrite("stage 1" & @CRLF)
$ht = _GDIPlus_ImageGetHeight($hImage)
ConsoleWrite("stage 2" & @CRLF)
$wd = _GDIPlus_ImageGetWidth($hImage)
ConsoleWrite($ht & ', ' & $wd & @CRLF)
;GUICtrlSetImage($pic1,$sFileName )
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Any suggestions?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You need to enclose the GDI+ Functions between _GDIPlus_Startup() and _GDIPLus_ShutDown()


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You need to enclose the GDI+ Functions between _GDIPlus_Startup() and _GDIPLus_ShutDown()

Oh yes, thanks, I completely forgot about that. :)

EDIT: Yup, works now.

#include <gdiplus.au3>
$sFileName = FileOpenDialog("pic","\","jpg(*.jpg)")
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$ht = _GDIPlus_ImageGetHeight($hImage)
$wd = _GDIPlus_ImageGetWidth($hImage)

msgbox(262144,'Size of ' & $sFileName & ' is', $ht & ' x ' & $wd);ConsoleWrite($ht & ', ' & $wd & @CRLF)
_GDIPlus_ImageDispose($hImage);added after reminder from progAndy
_GDIPLus_ShutDown()

EDIT 2: added _GDIPlus_ImageDispose($hImage)

EDIT 3!: Moved _GDIPLus_ShutDown() to end of script.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

:)

Don't forget _GDIPlus_ImageDispose($hImage) !


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This also works if you have the

Windows Image Acqusition Library installed

http://www.microsoft.com/downloads/details...lang=ennstalled

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <staticconstants.au3>
Const $SS_REALSIZEIMAGE = 0x800
#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 413, 298, 303, 219)
$Pic1 = GUICtrlCreatePic("", 48, 16, 100, 100, BitOR($SS_NOTIFY,$SS_REALSIZEIMAGE,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$sFileName = FileOpenDialog("pic","\","jpg(*.jpg)");tried bmp but no better
ConsoleWrite($sFileName & @CRLF)
$objImage = ObjCreate("WIA.ImageFile")
$objImage.LoadFile ($sFileName)
$ht = $objImage.Height
$wd = $objImage.Width
ConsoleWrite($ht & ', ' & $wd & @CRLF)
GUICtrlSetImage($pic1,$sFileName )
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by ResNullius

Share this post


Link to post
Share on other sites

I think Windows Image Acqusition Library works with GDI+, too because it needs Win XP, where GDI+ is available too. So GDI+ is the better solution, you don't have to install any additional software :)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Oh yes, thanks, I completely forgot about that. :)

EDIT: Yup, works now.

#include <gdiplus.au3>
$sFileName = FileOpenDialog("pic","\","jpg(*.jpg)")
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFileName)
$ht = _GDIPlus_ImageGetHeight($hImage)
$wd = _GDIPlus_ImageGetWidth($hImage)
_GDIPLus_ShutDown()
msgbox(262144,'Size of ' & $sFileName & ' is', $ht & ' x ' & $wd);ConsoleWrite($ht & ', ' & $wd & @CRLF)
_GDIPlus_ImageDispose($hImage);added after reminder from progAndy

EDIT 2: added _GDIPlus_ImageDispose($hImage)

AutoIt crashes for me after the msgbox display... :P

Share this post


Link to post
Share on other sites

:)

Don't forget _GDIPlus_ImageDispose($hImage) !

Of course I did. The benefit of not knowing much about something is that it should be easy to improve.

Post now corrected, thanks again.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Anyway to use gdiplus or an alternative to get the info for a pdf?

I have it working using the following code, but of course smaller would be better.

$file = FileOpenDialog("Please select file", "", "Image files (*.jpg;*.tif;*.gif;*.bmp;*.png;*.pdf)");
RunWait("C:\Program Files\IrfanView\i_view32.exe " & $file & "/info=" & $file & ".txt")
$dims = FileReadLine($file & ".txt", 6)
$cnt = StringInStr($dims, "=")
$dims = StringTrimLeft($dims, $cnt + 1)
$cnt = StringInStr($dims, "P")
$cnt = StringLen($dims) - $cnt
$dims = StringTrimRight($dims, $cnt + 2)
FileDelete($file & ".txt")
MsgBox("","",$dims)

Share this post


Link to post
Share on other sites

AutoIt crashes for me after the msgbox display... :)

That's because I put the ImageDispose after the _GDIPLus_ShutDown(). Not having a good day with this one. Thanks ResNullius, I'll correct it again.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

This code is much smaller, although also much bigger :) :

$sfile = @DesktopDir&'\pic.bmp'
msgbox ( 0, 'width, height', 'width: '&_GetExtProperty($sfile, 27)&' height: '&_GetExtProperty($sfile, 27))
;===============================================================================
; Function Name:    GetExtProperty($sPath,$iProp)
; Description:      Returns an extended property of a given file.
; Parameter(s):     $sPath - The path to the file you are attempting to retrieve an extended property from.
;                   $iProp - The numerical value for the property you want returned. If $iProp is is set
;                             to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
;                           The properties are as follows:
;                           Name = 0
;                           Size = 1
;                           Type = 2
;                           DateModified = 3
;                           DateCreated = 4
;                           DateAccessed = 5
;                           Attributes = 6
;                           Status = 7
;                           Owner = 8
;                           Author = 9
;                           Title = 10
;                           Subject = 11
;                           Category = 12
;                           Pages = 13
;                           Comments = 14
;                           Copyright = 15
;                           Artist = 16
;                           AlbumTitle = 17
;                           Year = 18
;                           TrackNumber = 19
;                           Genre = 20
;                           Duration = 21
;                           BitRate = 22
;                           Protected = 23
;                           CameraModel = 24
;                           DatePictureTaken = 25
;                           Dimensions = 26
;                           Width = 27
;                           Height = 28
;                           Company = 30
;                           Description = 31
;                           FileVersion = 32
;                           ProductName = 33
;                           ProductVersion = 34
; Requirement(s):   File specified in $spath must exist.
; Return Value(s):  On Success - The extended file property, or if $iProp = -1 then an array with all properties
;                   On Failure - 0, @Error - 1 (If file does not exist)
; Author(s):        Simucal (Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Func _GetExtProperty($sPath, $iProp)
    Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
    $iExist = FileExists($sPath)
    If $iExist = 0 Then
        SetError(1)
        Return "No file loaded"
    Else
        $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
        $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
        $oShellApp = ObjCreate ("shell.application")
        $oDir = $oShellApp.NameSpace ($sDir)
        $oFile = $oDir.Parsename ($sFile)
        If $iProp = -1 Then
            Local $aProperty[35]
            For $i = 0 To 34
                $aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
            Next
            Return $aProperty
        Else
            $sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
            If $sProperty = "" Then
                Return "None"
            Else
                Return $sProperty
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GetExtProperty

Share this post


Link to post
Share on other sites

Thanks Ludocus!

I'll add it to my slowly expanding knowledge base.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Thanks everybody for your help but for witdth and height that wrote pixel but i don't know how to fix it...

Edited by d3mon

No-life of autoit...what could be better ?LAST SCRIPTS WITH AUTO-IT : CLICK HERE

Share this post


Link to post
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
Sign in to follow this  
Followers 0