Sign in to follow this  
Followers 0
yair

memoery dispose in GDI

2 posts in this topic

#1 ·  Posted (edited)

the code bellow checks the correct printing orientation of a picture before silent printing in irfanview.

the full script gets a filename via a flash xmlsocket. so the meat of the script will sit inside a While 1 function.

as its going to run permanently~ i need help in understanding the various ways i can (should) dispose of image object memory footprint. were should i put the dispose/delete functions?

#include <GDIPlus.au3>
$fullPicPath = "C:\WINDOWS\system32\oobe\html\mouse\images\bulzanom.jpg"

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($fullPicPath)

; Extract image width and height
$width = _GDIPlus_ImageGetHeight($hImage)
$height = _GDIPlus_ImageGetWidth($hImage)

If $width >= $height Then; writes to irfan ini file the correct priniting orientation
    $orient = 0;portrait
Else
    $orient = 1;landscape
EndIf
IniWrite("C:\Program Files\IrfanView\i_view32.ini", "Print", "Orient", $orient)

; Clean up resources
;_GDIPlus_GraphicsDispose($hGraphic)
;_GDIPlus_ImageDispose($hBitmap)
;_WinAPI_DeleteObject($hBMP)


ShellExecute("C:\Program Files\IrfanView\i_view32.exe", $fullPicPath & " /print")

_GDIPlus_Shutdown()
Edited by yair

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

included is the complete script if someone finds the first too general, notice the checkOrinetation function for my GDI dilema.

#include <Date.au3>
#include <Constants.au3>
#include <GDIPlus.au3>

Global $port, $host, $pic_folder, $commandName
readParams()

$log = FileOpen("log.txt", 1)
logThis("start"); this function will log filenames and start stop script op

;=====TCP connect===========================
TCPStartup()
If @error <> 0 Then Exit
$MainSocket = TCPListen($host, $port); Create a Listening "SOCKET".
If $MainSocket = -1 Then Exit; If the Socket creation fails, exit.
$ConnectedSocket = -1; Initialize a variable to represent a connection
Do;Wait for and Accept a connection
    $ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
;==============================================

_GDIPlus_Startup()

While 1
    $recv = TCPRecv($ConnectedSocket, 2048); Try to receive (up to) 2048 bytes
    If @error Then ExitLoop
    If $recv <> "" Then
        $fileNameToPrint = BinaryToString($recv)
        $fullPicPath = $pic_folder & String($fileNameToPrint);for some reason i need to explicllctly turn it into a string, again?
        If FileExists($fullPicPath) Then
            checkOrinetation()
            ShellExecute("C:\Program Files\IrfanView\i_view32.exe", $fullPicPath & " /print")
            logThis($fullPicPath)
        EndIf
    EndIf
WEnd

If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)

Func checkOrinetation()
    $hImage = _GDIPlus_ImageLoadFromFile($fullPicPath)
; Extract image width and height
    $width = _GDIPlus_ImageGetHeight($hImage)
    $height = _GDIPlus_ImageGetWidth($hImage)
    If $width >= $height Then; writes to irfan ini file the correct priniting orientation
        $orient = 0;portrait
    Else
        $orient = 1;landscape
    EndIf
    IniWrite("C:\Program Files\IrfanView\i_view32.ini", "Print", "Orient", $orient)
; Clean up resources WHERE TO PUT, WHAT TO ENABLE
;_GDIPlus_GraphicsDispose($hImage)
;_GDIPlus_ImageDispose($hImage)
;_WinAPI_DeleteObject($hImage)
EndFunc ;==>checkOrinetation

Func OnAutoItExit()
    logThis("shotdown")
    TCPShutdown()
    _GDIPlus_Shutdown()
    FileClose("log.txt")
EndFunc ;==>OnAutoItExit

Func logThis($log)
    $tCur = _Date_Time_GetLocalTime()
    FileWriteLine("log.txt", _Date_Time_SystemTimeToDateTimeStr($tCur) & " >> " & $log)
EndFunc ;==>logThis

Func readParams()
; read formating from ini file
    $host = IniRead("params.ini", "network", "host", 0)
    $port = IniRead("params.ini", "network", "port", 65532)
    $pic_folder = IniRead("params.ini", "path", "pic_folder", "")
EndFunc ;==>readParams
Edited by yair

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