Jump to content

_GDIPlus_ImageResize Error - (Moved)


dejhost
 Share

Recommended Posts

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 by dejhost
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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

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

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

Link to comment
Share on other sites

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

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 by pixelsearch
Link to comment
Share on other sites

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

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

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 :

1876704569_overwritewithoutdispose.png.a3a9d79056fb3c849192bcdd74b8f1f3.png

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 by pixelsearch
Link to comment
Share on other sites

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

@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 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

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.

Link to comment
Share on other sites

@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

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 by dejhost
additional info inserted
Link to comment
Share on other sites

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:

  1. I just enabled #RequireAdmin once again - and the script  ran fine anyway.
  2. 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 by dejhost
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...