Jump to content
Sign in to follow this  
nullschritt

_GDIPlus_BitmapCreateFromMemory() Error 3

Recommended Posts

nullschritt

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?

Share this post


Link to post
Share on other sites
FireFox

Hi,

Can you post your script ?

Otherwise we can't guess what's wrong with it.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nullschritt

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

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nullschritt

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.

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nullschritt

My script runs just fine, as I said, comment out the functions that you don't have a library for... 

I already explained it wouldnt work otherwise.

Share this post


Link to post
Share on other sites
nullschritt

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.

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
nullschritt

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?

Share this post


Link to post
Share on other sites
nullschritt

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

Share this post


Link to post
Share on other sites
nullschritt

@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

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


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
Sign in to follow this  

×