ESPUser Posted August 20, 2021 Share Posted August 20, 2021 (edited) Hi, i tried this example from the helpfile. It creates and then loads an image @MyDocumentsDir & "\GDIPlus_Image.jpg" and i wanted to delete the image when the script ends. It seems impossible to delete the image when it has been used with _GDIPlus_ImageLoadFromFile even after _GDIPlus_ImageDispose($hImage) and _GDIPlus_Shutdown(). Can anyone tell me what i am doing wrong? Is there a way around this? expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> Example() Func Example() Local $hImage, $sCLSID, $tData, $tParams ; Screen Capture _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.jpg") ; Initialize GDI+ library _GDIPlus_Startup() ; Load image $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg") ; Get JPEG encoder CLSID $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") ; Set up parameters for 90 degree rotation $tData = DllStructCreate("int Data") DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data")) ; Save image with rotation _GDIPlus_ImageSaveToFileEx($hImage, @MyDocumentsDir & "\GDIPlus_Image2.jpg", $sCLSID, $tParams) ; Clean up resources _GDIPlus_ImageDispose($hImage) ; Shut down GDI+ library _GDIPlus_Shutdown() FileDelete(@MyDocumentsDir & "\GDIPlus_Image.jpg") ;ShellExecute(@MyDocumentsDir & "\GDIPlus_Image2.jpg") EndFunc ;==>Example Edited August 20, 2021 by ESPUser Link to comment Share on other sites More sharing options...
Dan_555 Posted August 20, 2021 Share Posted August 20, 2021 (edited) I'm not an expert with GDI, but i have played around, a bit, earlier. So far, i have discovered that, when you capture/load an image, with a handle, it gets locked (or it gets maked as being in use , by windows ? ). It is only when you free the handle that you can delete it. Therefore you can delete the file after using the _GDIPlus_ImageDispose($hImage) command. Edited August 20, 2021 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
ESPUser Posted August 20, 2021 Author Share Posted August 20, 2021 Thank you for your help, but as you can see above, i use ImageDispose before deleting and it does not work, even when i add some sleep time. Link to comment Share on other sites More sharing options...
Dan_555 Posted August 20, 2021 Share Posted August 20, 2021 (edited) After a bit of testing, the file(s) do get deleted only after _GDIPlus_ImageSaveToFileEx($hImage, @MyDocumentsDir & "\GDIPlus_Image2.jpg", $sCLSID, $tParams) is used , but not before; #include <GDIPlus.au3> #include <ScreenCapture.au3> Example() Func Example() Local $hImage, $sCLSID, $tData, $tParams ; Capture screen _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.jpg") ; Initialize GDI+ library _GDIPlus_Startup() ; Load image $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg") ; Get JPEG encoder CLSID $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") ; Set up parameters for 90 degree rotation $tData = DllStructCreate("int Data") DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data")) ; Save image with rotation _GDIPlus_ImageSaveToFileEx($hImage, @MyDocumentsDir & "\GDIPlus_Image2.jpg", $sCLSID, $tParams) FileDelete(@MyDocumentsDir & "\GDIPlus_Image.jpg") FileDelete(@MyDocumentsDir & "\GDIPlus_Image2.jpg") ; Shut down GDI+ library _GDIPlus_Shutdown() ;ShellExecute(@MyDocumentsDir & "\GDIPlus_Image2.jpg") EndFunc ;==>Example Edited August 20, 2021 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
ESPUser Posted August 20, 2021 Author Share Posted August 20, 2021 i tried your code and still only image2 gets deleted. The first image is still in the folder. Link to comment Share on other sites More sharing options...
ESPUser Posted August 20, 2021 Author Share Posted August 20, 2021 This works, no idea what i did wrong before...thanks for your help expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> Example() Func Example() Local $hImage, $sCLSID, $tData, $tParams ; Screen Capture _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.jpg") ; Initialize GDI+ library _GDIPlus_Startup() ; Load image $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg") ; Get JPEG encoder CLSID $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") ; Set up parameters for 90 degree rotation $tData = DllStructCreate("int Data") DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data")) ; Save image with rotation _GDIPlus_ImageSaveToFileEx($hImage, @MyDocumentsDir & "\GDIPlus_Image2.jpg", $sCLSID, $tParams) ; Clean up resources _GDIPlus_ImageDispose($hImage) ; Shut down GDI+ library _GDIPlus_Shutdown() FileDelete(@MyDocumentsDir & "\GDIPlus_Image.jpg") FileDelete(@MyDocumentsDir & "\GDIPlus_Image2.jpg") ;ShellExecute(@MyDocumentsDir & "\GDIPlus_Image2.jpg") EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now