Jump to content

Recommended Posts

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 post
Share on other sites
  • Solution

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 post
Share on other sites

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:

  1. Using _GDIPlus_StartUp and _GDIPlus_Shutdown
  2. Using _GDIPlus_ImageSavetoFileEx with encoding instead of _GDIPlus_ImageSavetoFile
  3. Using _GSIPlus_ImageDispose after the scaled image is saved

All now seems to be well and I'll know better next time.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By dRsrb
      Hi!

      It took me an hour to find out, that FileMove() doesn't work in _Example1(). But what's the reason?


      #Include <GDIPlus.au3> $sSource = 'C:\Wallpaper\AnyImage.jpg' $sDest = 'C:\Wallpaper\16_10\AnyImage.jpg' _Example1() ;~ _Example2() Func _Example1() _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sSource) _GDIPlus_ShutDown() FileMove($sSource, $sDest, 1 + 8) EndFunc Func _Example2() FileMove($sSource, $sDest, 1 + 8) EndFunc
      I wrote a small script to sort wallpapers by their aspect ratio (16:10, 16:9, 4:3, ...), but it doesn't work, because FileMove() doesn't move any images to the desired destination. At least it creates the directory structure.What could be the solution for this problem? _Example2() works as expected.

      My system:
      - AutoIt v3.3.6.1
      - SciTE v1.79
      - Windows 7 Ultimate (64-Bit)

      Bye
×
×
  • Create New...