Jump to content

_GDIPlus_BitmapCreateFromMemory() Error 3


Recommended Posts

Hello, this is probably a simple problem, but I'm not understanding whenever I call _GDIPlus_BitmapCreateFromMemory() I get @error=3.

I'm reading the image from a file, and convering the data to binary, but I still get  3 - unable to create bitmap from stream.

What step am I missing?

Link to comment
Share on other sites

If you are using the current beta (3.3.11.3) than _GDIPlus_BitmapCreateFromMemory has a typo in the function which causes not to run properly.

But I agree with FireFox, post your script that we can see what might be wrong.

Br,

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

You can comment out the _pixelgetcolor functions.

#include <_PixelGetColor.au3>

ToolTip(1)

$hDll = DllOpen("gdi32.dll")
$vDC = _PixelGetColor_CreateDC($hDll)

ToolTip(2)

;~ $a = TimerInit()
;~ CaptureNative($testMaxX, $testMaxY)
;~ $a1 = TimerDiff($a)

ToolTip(3)
$file = FileOpenDialog("Select an image", @ScriptDir, "All Files(*.*)")
$b = TimerInit()
$ret = CapturePixels(FileRead($file))
$b1 = TimerDiff($b)

ToolTip(4)

_PixelGetColor_ReleaseDC($vDC, $hDll)
DllClose($hDll)

ToolTip(5)

ConsoleWrite("Time   : " & $b1 & @CRLF)
ConsoleWrite($ret&@CRLF)


Func CapturePixels($data)
    $ret = ""
    $HBITMAP = _GDIPlus_BitmapCreateFromMemory($data)
    DllCall($hDll, "hwnd", "SelectObject", "int", $vDC, "hwnd", $HBITMAP)
    For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP)
        For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP)
            $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
        Next
    Next
    Return $ret
EndFunc   ;==>CaptureUDF
Link to comment
Share on other sites

I cannot see a _GDIPlus_Startup() in your script. Beside that, loading a bitmap from disk you can use _GDIPlus_BitmapCreateFromFile() or _GDIPlus_ImageLoadFromFile() instead.

Br,

UEZ

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

I cannot see a _GDIPlus_Startup() in your script. Beside that, loading a bitmap from disk you can use _GDIPlus_BitmapCreateFromFile() or _GDIPlus_ImageLoadFromFile() instead.

Br,

UEZ

 

I'm only loading it from the file because I didn't feel like putting binary in the reproducer script. The function is intended to process binary data.

Also in my script the udf function _PixelGetColor_CreateDC calls the _gdiplus_startup() function.

Link to comment
Share on other sites

Your script is not runable. Beside that your are mixing up GDI and GDI+.

Try this (untested):

#include <_PixelGetColor.au3>

ToolTip(1)

$hDll = DllOpen("gdi32.dll")
$vDC = _PixelGetColor_CreateDC($hDll)

ToolTip(2)

;~ $a = TimerInit()
;~ CaptureNative($testMaxX, $testMaxY)
;~ $a1 = TimerDiff($a)

ToolTip(3)
$file = FileOpenDialog("Select an image", @ScriptDir, "All Files(*.*)")
$b = TimerInit()
$hFile = FileOpen($file, 16)
$bin = FileRead($file)
FileClose($hFile)
$ret = CapturePixels($bin)
$b1 = TimerDiff($b)

ToolTip(4)

_PixelGetColor_ReleaseDC($vDC, $hDll)
DllClose($hDll)

ToolTip(5)

ConsoleWrite("Time   : " & $b1 & @CRLF)
ConsoleWrite($ret&@CRLF)


Func CapturePixels($data)
    $ret = ""
    $HBITMAP = _GDIPlus_BitmapCreateFromMemory($data, True)
    DllCall($hDll, "hwnd", "SelectObject", "int", $vDC, "hwnd", $HBITMAP)
    For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP)
        For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP)
            $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
        Next
    Next
    Return $ret
EndFunc   ;==>CaptureUDF

Br,

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

Your script is not runable. Beside that your are mixing up GDI and GDI+.

Try this (untested):

#include <_PixelGetColor.au3>

ToolTip(1)

$hDll = DllOpen("gdi32.dll")
$vDC = _PixelGetColor_CreateDC($hDll)

ToolTip(2)

;~ $a = TimerInit()
;~ CaptureNative($testMaxX, $testMaxY)
;~ $a1 = TimerDiff($a)

ToolTip(3)
$file = FileOpenDialog("Select an image", @ScriptDir, "All Files(*.*)")
$b = TimerInit()
$hFile = FileOpen($file, 16)
$bin = FileRead($file)
FileClose($hFile)
$ret = CapturePixels($bin)
$b1 = TimerDiff($b)

ToolTip(4)

_PixelGetColor_ReleaseDC($vDC, $hDll)
DllClose($hDll)

ToolTip(5)

ConsoleWrite("Time   : " & $b1 & @CRLF)
ConsoleWrite($ret&@CRLF)


Func CapturePixels($data)
    $ret = ""
    $HBITMAP = _GDIPlus_BitmapCreateFromMemory($data, True)
    DllCall($hDll, "hwnd", "SelectObject", "int", $vDC, "hwnd", $HBITMAP)
    For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP)
        For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP)
            $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
        Next
    Next
    Return $ret
EndFunc   ;==>CaptureUDF

Br,

UEZ

And sorry, but this doesn't fix it. Same behavior.

Link to comment
Share on other sites

This works:

 

;~ #include <_PixelGetColor.au3>
#include <GDIPlus.au3>

;~ ToolTip(1)

;~ $hDll = DllOpen("gdi32.dll")
;~ $vDC = _PixelGetColor_CreateDC($hDll)

;~ ToolTip(2)

;~ $a = TimerInit()
;~ CaptureNative($testMaxX, $testMaxY)
;~ $a1 = TimerDiff($a)

;~ ToolTip(3)
_GDIPlus_Startup()
$file = FileOpenDialog("Select an image", @ScriptDir, "All Files(*.*)")
$b = TimerInit()
$ret = CapturePixels(Binary(FileRead($file)))
$b1 = TimerDiff($b)
_GDIPlus_Shutdown()
;~ ToolTip(4)

;~ _PixelGetColor_ReleaseDC($vDC, $hDll)
;~ DllClose($hDll)

;~ ToolTip(5)

ConsoleWrite("Time   : " & $b1 & @CRLF)
ConsoleWrite($ret&@CRLF)


Func CapturePixels($data)
    $ret = ""
    $HBITMAP = _GDIPlus_BitmapCreateFromMemory($data, 1)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $HBITMAP = ' & $HBITMAP & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;~     DllCall($hDll, "hwnd", "SelectObject", "int", $vDC, "hwnd", $HBITMAP)
;~     For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP)
;~         For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP)
;~             $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
;~         Next
;~     Next
    _WinAPI_DeleteObject($HBITMAP)
    Return $ret
EndFunc   ;==>CaptureUDF
 

It seems that your pixel function shuts down GDI+ when returning and the file data is not send as binary.

Br,

UEZ

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

This works:

 

;~ #include <_PixelGetColor.au3>
#include <GDIPlus.au3>

;~ ToolTip(1)

;~ $hDll = DllOpen("gdi32.dll")
;~ $vDC = _PixelGetColor_CreateDC($hDll)

;~ ToolTip(2)

;~ $a = TimerInit()
;~ CaptureNative($testMaxX, $testMaxY)
;~ $a1 = TimerDiff($a)

;~ ToolTip(3)
_GDIPlus_Startup()
$file = FileOpenDialog("Select an image", @ScriptDir, "All Files(*.*)")
$b = TimerInit()
$ret = CapturePixels(Binary(FileRead($file)))
$b1 = TimerDiff($b)
_GDIPlus_Shutdown()
;~ ToolTip(4)

;~ _PixelGetColor_ReleaseDC($vDC, $hDll)
;~ DllClose($hDll)

;~ ToolTip(5)

ConsoleWrite("Time   : " & $b1 & @CRLF)
ConsoleWrite($ret&@CRLF)


Func CapturePixels($data)
    $ret = ""
    $HBITMAP = _GDIPlus_BitmapCreateFromMemory($data, 1)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $HBITMAP = ' & $HBITMAP & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;~     DllCall($hDll, "hwnd", "SelectObject", "int", $vDC, "hwnd", $HBITMAP)
;~     For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP)
;~         For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP)
;~             $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
;~         Next
;~     Next
    _WinAPI_DeleteObject($HBITMAP)
    Return $ret
EndFunc   ;==>CaptureUDF
 

It seems that your pixel function shuts down GDI+ when returning and the file data is not send as binary.

Br,

UEZ

 

For me it is happening in this way too, but I have treid with many files, all the same. Do you think it's an autoit bug?

Link to comment
Share on other sites

@UEZ How does that work for you? On my end I get same data. cannot get width, or or length of the file or it's color data from the handel.

 

See below, first time I check for data, script fails.:

;~ #include <_PixelGetColor.au3>
#include <GDIPlus.au3>

;~ ToolTip(1)

;~ $hDll = DllOpen("gdi32.dll")
;~ $vDC = _PixelGetColor_CreateDC($hDll)

;~ ToolTip(2)

;~ $a = TimerInit()
;~ CaptureNative($testMaxX, $testMaxY)
;~ $a1 = TimerDiff($a)

;~ ToolTip(3)
_GDIPlus_Startup()
$file = FileOpenDialog("Select an image", @ScriptDir, "All Files(*.*)")
$b = TimerInit()
$ret = CapturePixels(Binary(FileRead($file)))
$b1 = TimerDiff($b)
_GDIPlus_Shutdown()
;~ ToolTip(4)

;~ _PixelGetColor_ReleaseDC($vDC, $hDll)
;~ DllClose($hDll)

;~ ToolTip(5)

ConsoleWrite("Time   : " & $b1 & @CRLF)
ConsoleWrite($ret&@CRLF)


Func CapturePixels($data)
    $ret = ""
    $HBITMAP = _GDIPlus_BitmapCreateFromMemory($data, 1)
    _GDIPlus_ImageGetWidth($HBITMAP)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $HBITMAP = ' & $HBITMAP & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;~     DllCall($hDll, "hwnd", "SelectObject", "int", $vDC, "hwnd", $HBITMAP)
;~     For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP)
;~         For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP)
;~             $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
;~         Next
;~     Next
    _WinAPI_DeleteObject($HBITMAP)
    Return $ret
EndFunc   ;==>CaptureUDF
Link to comment
Share on other sites

Once AGAIN: you are mixing GDI and GDI+ stuff!

Using

_GDIPlus_BitmapCreateFromMemory($data, 1)

means the function returns a GDI bitmap which cannot be used in GDI+. Thus you cannot use _GDIPlus_ImageGetWidth($HBITMAP) afterwards!

 

Br,

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

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