Sign in to follow this  
Followers 0
Vert

GDI+ Trouble

3 posts in this topic

Hello,

I have created a script that downloads a PNG image, converts it to JPG, and then uses a splash screen to show it to the user. It is then supposed to get rid of these images, and loop through the entire process again.

However, the PNG file does not get deleted properly because it is already in use. Below is part of my code:

_GDIPlus_Startup()
    $image=_GDIPlus_ImageLoadFromFile("testpic.png")
    _GDIPlus_ImageSaveToFile($image,"testpic.jpg")
    _GDIPLus_ImageDispose("testpic.png")
    _WinAPI_DeleteObject($image)
    SplashImageOn("", "testpic.jpg", 80, 30, 0, 0)
    SplashOff()
    _GDIPlus_Shutdown()
    FileDelete("testpic.png")
    FileDelete("testpic.jpg")

The JPG file gets deleted with no problems, but the PNG file still persists, and therefore my script cannot continue to re-download a new image with the same name because it is already in use. Any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello,

I have created a script that downloads a PNG image, converts it to JPG, and then uses a splash screen to show it to the user. It is then supposed to get rid of these images, and loop through the entire process again.

However, the PNG file does not get deleted properly because it is already in use. Below is part of my code:

_GDIPlus_Startup()
    $image=_GDIPlus_ImageLoadFromFile("testpic.png")
    _GDIPlus_ImageSaveToFile($image,"testpic.jpg")
    _GDIPLus_ImageDispose("testpic.png")
    _WinAPI_DeleteObject($image)
    SplashImageOn("", "testpic.jpg", 80, 30, 0, 0)
    SplashOff()
    _GDIPlus_Shutdown()
    FileDelete("testpic.png")
    FileDelete("testpic.jpg")

The JPG file gets deleted with no problems, but the PNG file still persists, and therefore my script cannot continue to re-download a new image with the same name because it is already in use. Any ideas?

One thing I can see wrong is

_GDIPLus_ImageDispose("testpic.png")

should be

_GDIPLus_ImageDispose($image)

and

_WinAPI_DeleteObject($image) is not needed.

Try this.

;
#include <GDIPlus.au3>

_SpshJPG("File Name.png", 2000);in Script directory
_SpshJPG("C:\Full Path\File name.png", 3000)

Func _SpshJPG($FileName, $Time)
    Local $iX, $iY
    _GDIPlus_Startup()
    $image = _GDIPlus_ImageLoadFromFile($FileName)
    _GDIPlus_ImageSaveToFile($image, "testpic.jpg")
    $iX = _GDIPlus_ImageGetWidth($image)
    $iY = _GDIPlus_ImageGetHeight($image)
    SplashImageOn("", "testpic.jpg", $iX, $iY, (@DesktopWidth - $iX) / 2, (@DesktopHeight - $iX) / 2)
    Sleep($Time)
    SplashOff()

    _GDIPlus_ImageDispose($image)
    _GDIPlus_Shutdown()
;FileDelete("testpic.png")
    FileDelete("testpic.jpg")
    Return
EndFunc  ;==>_SpshJPG
;
Edited by Malkey

Share this post


Link to post
Share on other sites

Works great now, thanks for the help!

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