Jump to content

GDIplus not working in For loop


Recommended Posts

I'm having some issues with getting this GDI_plus script to work. I keep getting a _GDIPlus_BitmapCreateFromScan0 error. And towards the top of the script where I have the _ArrayDisplay, the ConsoleWrite underneath the _ArrayDisplay won't write any output which is weird because when I uncheck the _ArrayDisplay it shows everything.

 

Error:

(53) : ==> Subscript used on non-accessible variable.:

$hBitmap_Neg = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1])
$hBitmap_Neg = _GDIPlus_BitmapCreateFromScan0($aDim^ ERROR

 

Full code -

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
Global $imagesfolder, $imagelist
Global $hImage, $aDim, $hImage_Negative
Global $aDim, $hBitmap_Neg, $hGfx, $hIA, $tNegMatrix, $pNegMatrix

GDIplus_Convert()

Func GDIplus_Convert()

    $imagesfolder = @ScriptDir & "\Images\" ; folder where the images are stored.
    If @error Then ; If you don't choose any folder then you'll get an error and the script will Exit
        MsgBox($MB_SYSTEMMODAL, "ERROR", "folders has no images")
        Exit
    Else
        ConsoleWrite("folder: " & $imagesfolder & @CRLF)
    EndIf

    $imagelist = _FileListToArray($imagesfolder, "*.*", 1, True)

    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    Else
        ; Display the results returned by _FileListToArray.
        ;_ArrayDisplay($imagelist, "Images found")
        ConsoleWrite("Image found " & $imagelist & @CRLF) ; This is not working for some reason (_ArrayDisplay work tho..?)
    EndIf

    For $i = 1 To $imagelist[0]

        $hImage = $imagelist[$i]

        _GDIPlus_Startup()
        $hImage = _GDIPlus_ImageLoadFromFile($hImage)
        $aDim = _GDIPlus_ImageGetDimension($hImage)
        $hImage_Negative = _GDIPlus_BitmapCreateNegative($hImage)

        _GDIPlus_ImageSaveToFile($hImage_Negative, @ScriptDir & "\Images\" & "GDIplus_" & $imagelist)

        _GDIPlus_ImageDispose($hImage_Negative)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()

    Next

EndFunc   ;==>GDIplus_Convert

Func _GDIPlus_BitmapCreateNegative($hBitmap)
     $aDim = _GDIPlus_ImageGetDimension($hBitmap)
     $hBitmap_Neg = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1])
     $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap_Neg)
     $hIA = _GDIPlus_ImageAttributesCreate()
     $tNegMatrix = _GDIPlus_ColorMatrixCreateNegative()
     $pNegMatrix = DllStructGetPtr($tNegMatrix)
    _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pNegMatrix)
    _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hBitmap, 0, 0, $aDim[0], $aDim[1], 0, 0, $aDim[0], $aDim[1], $hIA)
    _GDIPlus_ImageAttributesDispose($hIA)
    _GDIPlus_GraphicsDispose($hGfx)
    Return $hBitmap_Neg
EndFunc   ;==>_GDIPlus_BitmapCreateNegative

 

Edited by aa2zz6
Link to comment
Share on other sites

Seems like not image file in folder. Try this

...
    _GDIPlus_Startup()
    For $i = 1 To $imagelist[0]

        $sPath = $imagelist[$i]
        $hImage = _GDIPlus_ImageLoadFromFile($sPath)
        If @error Then ContinueLoop

        $hImage_Negative = _GDIPlus_BitmapCreateNegative($hImage)

        $sName = StringMid($sPath, StringInStr($sPath, "\", 1, -1) + 1)
        _GDIPlus_ImageSaveToFile($hImage_Negative, @ScriptDir & "\Images\GDIplus_" & $sName)

        _GDIPlus_ImageDispose($hImage_Negative)
        _GDIPlus_ImageDispose($hImage)

    Next
    _GDIPlus_Shutdown()
...

 

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