Jump to content

Cant Delete Image after using GDIPlus...


Recommended Posts

Hello, all, i have a problem and hope you may have solution. My problem is that i cant delete image after using GDIPlus function.

Here is my code:

Problem.au3

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Color.au3>

$sBMP_Path1 = @ScriptDir & "\Test.bmp"
$GuiSizeX = 74
$GuiSizeY = 130
Compare()

Func Compare()
    Local $v_Values[$GuiSizeX + 1][$GuiSizeY + 1], $count = 0, $Var = 0
    _GDIPlus_Startup()
    If not FileExists($sBMP_Path1) Then
        _GDIPlus_Shutdown()
        MsgBox(32,"Error","Why you didnt put image?")
        Exit
    EndIf
    $hBMPBuff1 = _GDIPlus_BitmapCreateFromFile($sBMP_Path1)
    $Reslt = _GDIPlus_BitmapLockBits($hBMPBuff1, 0, 0, $GuiSizeX, $GuiSizeY, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $stride = DllStructGetData($Reslt, "stride")
    $Scan0 = DllStructGetData($Reslt, "Scan0")
    For $i = 0 To $GuiSizeX - 1
    For $j = 0 To $GuiSizeY - 1
            $count = $count + 1
    $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4))
    $v_Values[$i][$j] = DllStructGetData($v_Buffer, 1)
    Next
    Next
    _GDIPlus_BitmapUnlockBits($hBMPBuff1, $Reslt)
    _GDIPlus_BitmapDispose($hBMPBuff1)
    _GDIPlus_Shutdown()
    ConsoleWrite("Pixels number: " & $count & @CRLF)
    FileDelete($hBMPBuff1)
    Return
EndFunc

Thanks, as always, for any answers.

FileDelete($hBMPBuff1)

This line in your script should not work.

$hBMPBuff1 is a handle to a bitmap object created from a file using _GDIPlus_BitmapCreateFromFile function.

In the help file under _GDIPlus_BitmapCreateFromFile there is mentioned a related file _WinAPI_DeleteObject which is used to delete a bitmap.

So to clean up the bitmap object, _WinAPI_DeleteObject ($hBMPBuff1) should be used.

If you wish to delete the bmp image file from your hard drive, then FileDelete(@ScriptDir & "\Test.bmp") should be used.

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