dejhost Posted December 4, 2019 Share Posted December 4, 2019 (edited) Hi all, I have the following code ;save image temp _GDIPlus_ImageSaveToFile ( $hImage, @ScriptDir & "\resized" & $path[4]) If @error <> 0 Then Then MsgBox(0,"_GDIPlus_ImageResize()_2","@error = " & @error & ", and extended error = " & @extended ) ;save image temp _GDIPlus_ImageSaveToFile ( $hImage, @ScriptDir & "\resized" & $path[4]) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_2","@error = " & @error & ", and extended error = " & @extended ) and get the following error message: Quote @error = 10, and extended error = 7 Asking google, I find: Quote Global Const $GDIP_ERRWIN32ERROR = 7 ; The method generated a Microsoft Win32 error Can anybody tell me what this really means, and how to troubleshoot? The error does only appear occasionally, and I do not manage to identify the reason. Thank you! Edited December 4, 2019 by dejhost Link to comment Share on other sites More sharing options...
Nine Posted December 4, 2019 Share Posted December 4, 2019 Very hard to say with those 2 lines of code without having the rest of the script. Like you should know by now, making a runable snippet that reproduces the error will likely incite us to help you. “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...
Moderators JLogan3o13 Posted December 4, 2019 Moderators Share Posted December 4, 2019 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
pixelsearch Posted December 4, 2019 Share Posted December 4, 2019 I have this in one of my scripts : _GDIPlus_ImageSaveToFile($hImage_Resized, $sFileName) If @error Then ; could be a read-only file error (tried it: @error = 10 and @extended =7) $iKeep_error = @error $iKeep_extended = @extended If Not ($iKeep_error = 10 And $iKeep_extended = 7) Then _Exit("_GDIPlus_ImageSaveToFile", $sFileName, $iKeep_error, $iKeep_extended) Else ; $iKeep_error = 10 And $iKeep_extended = 7 : maybe a read-only file ? _Treat_SaveToFile($hImage_Resized, $sFileName, $iKeep_error, $iKeep_extended) EndIf Else ... EndIf Could you check if your image isn't read-only ? Link to comment Share on other sites More sharing options...
dejhost Posted December 5, 2019 Author Share Posted December 5, 2019 Func _DrawImage() ;_GDIPlus_Startup() ;If @error Then Exit MsgBox(0x40010, "Error", "GDI+ Did not start up correctly!") ;get dimensions of orig. image $hImage = _GDIPlus_ImageLoadFromFile($sFile) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) ;resize image If ($iWidth > (@DesktopWidth*3/4)) Then $hImage = _GDIPlus_ImageResize($hImage, Round(@DesktopWidth*3/4), Round((@DesktopWidth*3/4)*($iHeight/$iWidth)) ) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_1","@error = " & @error & ", and extended error = " & @extended) EndIf ;save image temp If FileExists(@ScriptDir & "\resized" & $path[4]) Then FileDelete(@ScriptDir & "\resized" & $path[4]) EndIf _GDIPlus_ImageSaveToFile ( $hImage, @ScriptDir & "\resized" & $path[4]) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_2","@error = " & @error & ", and extended error = " & @extended ) Thanks for moving the post and your comments. Find above the surrounding source code. Considering that I always use the same image for testing purposes, the image in question gets overwritten (see the last 2 lines, causing the error). I now delete the previous existing image, so write-protection shouldn't be an issue in the future. I will let you know if this does the trick. As I said - the error does not repeat everytime the script runs, so I will observe this a few days. Link to comment Share on other sites More sharing options...
Nine Posted December 5, 2019 Share Posted December 5, 2019 You shouldn't use the same handle for the resized image as the original one, create a new variable. Make sure you dispose both images after saving to file. “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...
dejhost Posted December 5, 2019 Author Share Posted December 5, 2019 Unfortunately, this did not the trick - the error reappeared 😞 Link to comment Share on other sites More sharing options...
dejhost Posted December 5, 2019 Author Share Posted December 5, 2019 Unfortunately, this did not the trick - the error reappeared 😞 Quote You shouldn't use the same handle for the resized image as the original one, create a new variable. Make sure you dispose both images after saving to file. Shall do! Thanks! Link to comment Share on other sites More sharing options...
pixelsearch Posted December 5, 2019 Share Posted December 5, 2019 (edited) 6 hours ago, Nine said: You shouldn't use the same handle for the resized image as the original one, Yes that's true . Also ImageDispose is important when you overwrite : $hImage_Resized = _GDIPlus_ImageResize($hImage, $iX_resized, $iY_resized) If @error Then ; damaged image (@error = 4 and @extended = 0), see @error = 4 in help file ... EndIf _GDIPlus_ImageDispose($hImage) ; place it HERE, required if file will be overwritten _GDIPlus_ImageSaveToFile($hImage_Resized, $sFileName) When you got images saving/resizing issues like this, try always to find UEZ's scripts, they're a big help Edited December 5, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
dejhost Posted December 6, 2019 Author Share Posted December 6, 2019 thx, pixelsearch. I have now moved the Disposal to the correct line. Prior doing so, the error reappeared. The code looks like this now: Func _DrawImage() ;_GDIPlus_Startup() ;If @error Then Exit MsgBox(0x40010, "Error", "GDI+ Did not start up correctly!") ;get dimensions of orig. image $hImage = _GDIPlus_ImageLoadFromFile($sFile) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) ;resize image If ($iWidth > (@DesktopWidth*3/4)) Then $hImageresized = _GDIPlus_ImageResize($hImage, Round(@DesktopWidth*3/4), Round((@DesktopWidth*3/4)*($iHeight/$iWidth)) ) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_1","@error = " & @error & ", and extended error = " & @extended) EndIf _GDIPlus_ImageDispose($hImage) ; place it HERE, required if file will be overwritten ;save image temp If FileExists(@ScriptDir & "\resized" & $path[4]) Then FileDelete(@ScriptDir & "\resized" & $path[4]) EndIf _GDIPlus_ImageSaveToFile ($hImageresized, @ScriptDir & "\resized" & $path[4]) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_2","@error = " & @error & ", and extended error = " & @extended ) Link to comment Share on other sites More sharing options...
UEZ Posted December 6, 2019 Share Posted December 6, 2019 Can you add these two lines before you save the result? ;save image temp If FileExists(@ScriptDir & "\resized" & $path[4]) Then FileDelete(@ScriptDir & "\resized" & $path[4]) EndIf ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ScriptDir & "\resized" & $path[4] = ' & @ScriptDir & "\resized" & $path[4] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hImageresized = ' & $hImageresized & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _GDIPlus_ImageSaveToFile ($hImageresized, @ScriptDir & "\resized" & $path[4]?) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_2","@error = " & @error & ", and extended error = " & @extended ) What is the output of both ConsoleWrite lines when it fails? Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
pixelsearch Posted December 6, 2019 Share Posted December 6, 2019 (edited) Hey UEZ is here, now we're lucky This is what I tested right now, it could be an important step to solve dejhost's issue : error 10 and extended 7 happen in (at least) these both cases, when you choose to overwrite the original image : 1) File is read-only on disk and you want to overwrite it (that was my 1st suggestion) 2) File is not read-only on disk, but you comment the mandatory _GDIPlus_ImageDispose($hImage) line, i.e : $hImage_Resized = _GDIPlus_ImageResize($hImage, $iX_resized, $iY_resized) ; _GDIPlus_ImageDispose($hImage) ; place it HERE, required if file will be overwritten _GDIPlus_ImageSaveToFile($hImage_Resized, $sFileName) ending with : In fact, both cases look a bit similar, because if you don't dispose the (non read-only) original image before overwriting it, its handle $himage grabbed the original image and won't let you overwrite it in any way because you didn't release it... acting just like a read-only attribute. Edited December 6, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
dejhost Posted December 6, 2019 Author Share Posted December 6, 2019 Here is the current code: Func _DrawImage() ;get dimensions of orig. image $hImage = _GDIPlus_ImageLoadFromFile($sFile) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) ;resize image If ($iWidth > (@DesktopWidth*3/4)) Then $hImageresized = _GDIPlus_ImageResize($hImage, Round(@DesktopWidth*3/4), Round((@DesktopWidth*3/4)*($iHeight/$iWidth)) ) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_1","@error = " & @error & ", and extended error = " & @extended) EndIf _GDIPlus_ImageDispose($hImage) ; place it HERE, required if file will be overwritten ;save image temp If FileExists(@ScriptDir & "\resized" & $path[4]) Then FileDelete(@ScriptDir & "\resized" & $path[4]) EndIf ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ScriptDir & "\resized" & $path[4] = ' & @ScriptDir & "\resized" & $path[4] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hImageresized = ' & $hImageresized & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _GDIPlus_ImageSaveToFile ($hImageresized, @ScriptDir & "\resized" & $path[4]) If @error <> 0 Then MsgBox(0,"_GDIPlus_ImageResize()_2","@error = " & @error & ", and extended error = " & @extended ) The Error message relates to the last line in the code above: Quote @error = 10, and extended error = 7 The sonsole shows nothing exiting (anonymized:) Quote >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\...\GDIv.37.au3" /UserParams +>15:59:13 Starting AutoIt3Wrapper v.15.729.1555.1 SciTE v.3.5.4.0 Keyboard:00000414 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0407) +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\...\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\...\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.0) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\J...\GDIv.37.au3 +>15:59:13 AU3Check ended.rc:0 >Running:(3.3.14.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\....\GDIv.37.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop +>15:59:13 AutoIt3.exe ended.rc:0 +>15:59:13 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.15 Link to comment Share on other sites More sharing options...
UEZ Posted December 6, 2019 Share Posted December 6, 2019 (edited) @dejhost do you start the script with admin privileges? If so then turn it off to show console messages. Can it be that you have an permission issue with the folder where you want to save the resized image? Edited December 9, 2019 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Nine Posted December 6, 2019 Share Posted December 6, 2019 Someone must tell him, that debugging involves having at EVERY statement a ConsoleWrite to check for @error and resulting returns from the functions. Basic basic programming skill. “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...
dejhost Posted December 9, 2019 Author Share Posted December 9, 2019 @UEZ: Neither Scite nor the source code has administrator privileges. However, the Scriptdirectory shows "Read-only for one+ of the containing files. If I remove the setting and run the script, the properties of the scriptdirectory jump back to what they were before. But I cannot identify the responsible files. Looking at all the files that get a new "DAte modified" while running the script, none has "read-only" permission. I will search the web to find out why I do not get the expected console output. Maybe a setting in Scite. Link to comment Share on other sites More sharing options...
dejhost Posted December 9, 2019 Author Share Posted December 9, 2019 (edited) I realize now that I actually have a #RequireAdmin in the header. This seems to be responsible for the missing consolewrite output. I disabled it and set Scite to "run as administrator" - which seems to do the trick. Edited December 9, 2019 by dejhost additional info inserted Link to comment Share on other sites More sharing options...
UEZ Posted December 9, 2019 Share Posted December 9, 2019 And what is the result of the two ConsoleWrite lines when it fails? Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
dejhost Posted December 9, 2019 Author Share Posted December 9, 2019 46 minutes ago, UEZ said: And what is the result of the two ConsoleWrite lines when it fails? The error hasn't reappeared yet. I will post as soon as it does! Link to comment Share on other sites More sharing options...
dejhost Posted December 12, 2019 Author Share Posted December 12, 2019 (edited) It seems that the error does not reappear and the issue is solved. I get the following output everytime I run: Quote @@ Debug(172) : @ScriptDir & "\resized" & $path[4] = C:\Users\Jost Wittmann\Documents\Privat\Promotion\Project work\Heidrun Bildanalyse\Autoit Script\resized.jpg >Error code: 0 @@ Debug(173) : $hImageresized = 0x07432140 >Error code: 0 @@ Debug(177) : _GDIPlus_ImageSaveToFile($hImageresized, @ScriptDir & "\resized" & $Path[4]) = True >Error code: 0 It is my understanding that the #RequireAdmin caused write-issues, because the error did not reappear after this expression was disabled. But I have still difficulties to reproduce the error in a reliable manner: I just enabled #RequireAdmin once again - and the script ran fine anyway. I then disabled the _GDIPlus_ImageDispose($hImage) (in addition to the enabled #RequireAdmin) - yet, the script ran fine. The properties of the folder containing all files (the script and the images) is still set to "Read Only" (for some of the files) by the script every time it runs. But it does not cause any troubles. So although the problem is solved for me, I'm happy to troubleshoot some more in order to identify the issue more precisely. Might help other people in the future. But I would need some instructions for this. Thank you for all your input so far! Edited December 16, 2019 by dejhost 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