nullschritt Posted February 10, 2014 Posted February 10, 2014 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?
FireFox Posted February 10, 2014 Posted February 10, 2014 (edited) Hi, Can you post your script ? Otherwise we can't guess what's wrong with it. Br, FireFox. Edited February 10, 2014 by FireFox
UEZ Posted February 10, 2014 Posted February 10, 2014 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
nullschritt Posted February 10, 2014 Author Posted February 10, 2014 You can comment out the _pixelgetcolor functions. expandcollapse popup#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
UEZ Posted February 10, 2014 Posted February 10, 2014 (edited) 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 February 10, 2014 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
nullschritt Posted February 10, 2014 Author Posted February 10, 2014 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.
UEZ Posted February 10, 2014 Posted February 10, 2014 Your script is not runable. Beside that your are mixing up GDI and GDI+. Try this (untested): expandcollapse popup#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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
nullschritt Posted February 10, 2014 Author Posted February 10, 2014 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.
nullschritt Posted February 10, 2014 Author Posted February 10, 2014 Your script is not runable. Beside that your are mixing up GDI and GDI+. Try this (untested): expandcollapse popup#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.
UEZ Posted February 10, 2014 Posted February 10, 2014 (edited) This works: expandcollapse popup;~ #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 February 10, 2014 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
nullschritt Posted February 11, 2014 Author Posted February 11, 2014 This works: expandcollapse popup;~ #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?
nullschritt Posted February 11, 2014 Author Posted February 11, 2014 @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.
nullschritt Posted February 11, 2014 Author Posted February 11, 2014 @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.: expandcollapse popup;~ #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
UEZ Posted February 11, 2014 Posted February 11, 2014 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now