Fritterandwaste Posted January 11, 2023 Share Posted January 11, 2023 Hi I am having problems loading an image using _GDIPlus_ImageLoadFromFile. Each attempt fails at the "Load error" line of code which shows an error code of 1. The same error code is returned if the file does not exist yet these files do exist and I am supplying the full path of the file required within the local filesystem. Also, if I copy and paste the text of the file path from the debug statement in the code into a command prompt and hit enter, it will display the image in question. These are all jpg files created using INetGet. Where might I be going wrong please? Any help would be appreciated. My code is below. If FileExists($aImgLst[$j]) Then FnuDebug("jpg: " & $aImgLst[$j]) $hBitmap1 = _GDIPlus_ImageLoadFromFile($aImgLst[$j]) If @error<>0 then MsgBox(0,"", "Load error " & @error & ", handle=" & $hBitmap1) $hBitMap2 = _GDIPlus_ImageScale($hBitMap1, $dScale, $dScale) If @error<>0 then MsgBox(0,"", "Scale error " & @error) If _GDIPlus_ImageSaveToFile($hBitMap2,$aImgLst[$j] & "Small") <> True Then MsgBox(0,"", "Image error: " & @error & " (" & $hBitMap2 & ")") EndIf EndIf Thank you. Link to comment Share on other sites More sharing options...
Nine Posted January 12, 2023 Share Posted January 12, 2023 Make a runable reproducible script (with all the parts needed) then we can help you out. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Solution Trong Posted January 12, 2023 Solution Share Posted January 12, 2023 Take a look at the example script: #include <GDIPlus.au3> Global $iImageFile_IN = "C:\Users\Administrator\Desktop\example.jpg" Global $iImageFile_OUT = "C:\Users\Administrator\Desktop\example_Scale.jpg" Global $iImage_Encoder = "JPG" Global $iImage_Scaled = 2.75 ;1.0 is without any scaling FileDelete($iImageFile_OUT) If FileExists($iImageFile_IN) Then ConsoleWrite("- Image processing... " & $iImageFile_IN & @CRLF) _GDIPlus_Startup() ; Initialize GDI+ library Local $hImage = _GDIPlus_ImageLoadFromFile($iImageFile_IN) If @error <> 0 Then ConsoleWrite("! 1 ImageLoad error " & @error & @CRLF) Local $hImage_Scaled = _GDIPlus_ImageScale($hImage, $iImage_Scaled, $iImage_Scaled) If @error <> 0 Then ConsoleWrite("! 2 Scale error " & @error & @CRLF) ; Get JPEG encoder CLSID Local $sCLSID = _GDIPlus_EncodersGetCLSID($iImage_Encoder) If @error <> 0 Then ConsoleWrite("! 3 Encoder error " & @error & @CRLF) ; Save image _GDIPlus_ImageSaveToFileEx($hImage_Scaled, $iImageFile_OUT, $sCLSID) If @error <> 0 Then ConsoleWrite("! 4 ImageSaveToFile error " & @error & @CRLF) Else ConsoleWrite("- DONE " & @CRLF) ShellExecute($iImageFile_OUT) EndIf _GDIPlus_Shutdown() ; Shut down GDI+ library Else MsgBox(64, "", "Image not Exists: " & $iImageFile_IN) EndIf Regards, Link to comment Share on other sites More sharing options...
Fritterandwaste Posted January 12, 2023 Author Share Posted January 12, 2023 Thank you both. I'll take a close look at your script VIP. Maybe it's the GdiPlus_Startup that's the problem, I haven't used that. Link to comment Share on other sites More sharing options...
AutoBert Posted January 12, 2023 Share Posted January 12, 2023 49 minutes ago, Fritterandwaste said: Maybe it's the GdiPlus_Startup that's the problem, I haven't used that. Quote Remarks Call _GDIPlus_Startup() before you create any GDI+ objects. Link to comment Share on other sites More sharing options...
Fritterandwaste Posted January 12, 2023 Author Share Posted January 12, 2023 Ok, first of all, thank you once again all and to VIP in particular. I clearly have a lot to learn in this area. I made changes as follows: Using _GDIPlus_StartUp and _GDIPlus_Shutdown Using _GDIPlus_ImageSavetoFileEx with encoding instead of _GDIPlus_ImageSavetoFile Using _GSIPlus_ImageDispose after the scaled image is saved All now seems to be well and I'll know better next time. 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