Morrison Posted July 28, 2011 Posted July 28, 2011 Hi! I´m trying to build me a Filter & Pixel prog for image analysis! But I´m getting just a black pic at the end! Who can give me any hints or solutions? thx expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Local $hBitmap, $hImage, $sImageType, $iX, $iY, $iXc, $iYc, $iMemo, $iPixelColor, $Count, $File, $color1, $oForm, $color, $dc, $setpixel, $realesedc Local $hGraphic, $hBitmap, $hBackbuffer, $save, $hPen, $hWind $color1 = 0x000000 $File = FileOpen(@DesktopDir & "\coords.txt", 2) _Main() Func _Main() _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\jdriscoll.jpg") $sImageType = _GDIPlus_EncodersGetCLSID("JPG") $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $oForm = GUICreate("GDI+", ($iX), ($iY)) GUISetBkColor(0xFFFFFF) ;$iMemo = GUICtrlCreateEdit("", 0, 0, ($iX + 25), ($iY + 25)) GUISetState() $hWind = WinGetHandle($oForm) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWind) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;PixelCount For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 $iPixelColor = Hex(_GDIPlus_GetPixel($hImage, $iXc, $iYc), 6) If Dec($iPixelColor) < 3947582 Then $Count = $Count + 1 FileWrite($File, $iXc & "," & $iYc & @CRLF) ;MemoWrite("X= " & $iXc & " / Y= " & $iYc) SetPixel($oForm, $iXc, $iYc, $color) $hPen = _GDIPlus_PenCreate(0x000000); _GDIPlus_GraphicsDrawLine ($hBackbuffer, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) _GDIPlus_GraphicsDrawLine ($hGraphic, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) EndIf Next Next $save = _GDIPlus_ImageSaveToFile($hBitmap,@ScriptDir & '\Image1.jpg') Do Until GUIGetMsg() = $GUI_EVENT_CLOSE FileClose($File) _GDIPlus_Shutdown() EndFunc ;==>_Main ; Gibt eine Zeile im Memo-Fenster aus Func MemoWrite($sMessage = '') GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; _GDIPlus_GetPixel Func _GDIPlus_GetPixel($hBitmap, $X, $Y) Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $X, "int", $Y, "dword*", 0) If @error Then Return SetError(1, 0, 0) Return SetError($result[0], 1, $result[4]) EndFunc ;==>_GDIPlus_GetPixel ;SetPixel Func SetPixel($oForm, $X, $Y, $color) $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $oForm) $setpixel = DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $X, "long", $Y, "long", $color) $realesedc = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc ;==>SetPixelFilter.rar
martin Posted July 28, 2011 Posted July 28, 2011 Hi!I´m trying to build me a Filter & Pixel prog for image analysis!But I´m getting just a black pic at the end! Who can give me any hints or solutions?thxI'm not sure what you're trying to achieve but it looks to me as though you should be using $PixelColour not $color on line 40, and the next 3 lines just erase the picture so it was easier fo rme to see what was happening if I commented them out. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
dragan Posted July 28, 2011 Posted July 28, 2011 You didn't "publish" the things you drew that's why you have black graphic. (and as for drawing I suggest you draw only on backbuffer). Once you draw all things you want to be drawn just post this function: _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iX, $iY)
Morrison Posted July 28, 2011 Author Posted July 28, 2011 Solution: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Local $hBitmap, $hImage, $sImageType, $iX, $iY, $iXc, $iYc, $iMemo, $iPixelColor, $Count, $File, $color1, $oForm, $color, $dc, $setpixel, $realesedc Local $hGraphic, $hBitmap, $hBackbuffer, $save, $hPen, $hWind $color1 = 0x000000 $File = FileOpen(@DesktopDir & "\coords.txt", 2) _Main() Func _Main() _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\jdriscoll.jpg") $sImageType = _GDIPlus_EncodersGetCLSID("JPG") $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $oForm = GUICreate("GDI+", ($iX), ($iY)) GUISetBkColor(0xFFFFFF) ;$iMemo = GUICtrlCreateEdit("", 0, 0, ($iX + 25), ($iY + 25)) GUISetState() $hWind = WinGetHandle($oForm) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWind) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic) $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF) ;PixelCount For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 $iPixelColor = Hex(_GDIPlus_GetPixel($hImage, $iXc, $iYc), 6) If Dec($iPixelColor) < 3947582 Then $Count = $Count + 1 FileWrite($File, $iXc & "," & $iYc & @CRLF) ;MemoWrite("X= " & $iXc & " / Y= " & $iYc) SetPixel($oForm, $iXc, $iYc, $color) $hPen = _GDIPlus_PenCreate(0xFF000000); _GDIPlus_GraphicsDrawLine ($hBackbuffer, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) _GDIPlus_GraphicsDrawLine ($hGraphic, $iXc, $iYc, $iXc + 1, $iYc + 1, $hPen) EndIf Next Next $save = _GDIPlus_ImageSaveToFile($hBitmap,@ScriptDir & '\Image1.jpg') Do Until GUIGetMsg() = $GUI_EVENT_CLOSE FileClose($File) _GDIPlus_Shutdown() EndFunc ;==>_Main ; Gibt eine Zeile im Memo-Fenster aus Func MemoWrite($sMessage = '') GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite ; _GDIPlus_GetPixel Func _GDIPlus_GetPixel($hBitmap, $X, $Y) Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $X, "int", $Y, "dword*", 0) If @error Then Return SetError(1, 0, 0) Return SetError($result[0], 1, $result[4]) EndFunc ;==>_GDIPlus_GetPixel ;SetPixel Func SetPixel($oForm, $X, $Y, $color) $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $oForm) $setpixel = DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $X, "long", $Y, "long", $color) $realesedc = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) EndFunc ;==>SetPixel
dragan Posted July 28, 2011 Posted July 28, 2011 this might work as well: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> _Main() Func _Main() Local $Count = 0 Local $File = FileOpen(@DesktopDir & "\coords.txt", 2) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\jdriscoll.jpg") Local $iX = _GDIPlus_ImageGetWidth($hImage) Local $iY = _GDIPlus_ImageGetHeight($hImage) Local $oForm = GUICreate("GDI+", ($iX), ($iY)) GUISetState() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($oForm) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $hGraphic) Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) Local $BrushBckr = _GDIPlus_BrushCreateSolid(0xFFFFFF00) _GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $iX, $iY, $BrushBckr) ;PixelCount For $iXc = 0 To $iX - 1 For $iYc = 0 To $iY - 1 $iPixelColor = Hex(_GDIPlus_GetPixel($hImage, $iXc, $iYc), 6) If Dec($iPixelColor) < 0x3C3C3C then;3947582 Then $Count = $Count + 1 FileWrite($File, $iXc & "," & $iYc & @CRLF) _GDIPlus_GraphicsFillRect($hBackbuffer, $iXc, $iYc, 1, 1) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iX, $iY) EndIf Next Next Local $GC = _GDIPlus_ImageGetGraphicsContext($hBitmap) Local $newBmp = _GDIPlus_BitmapCreateFromGraphics($iX, $iY, $GC) Local $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp) _GDIPlus_GraphicsDrawImageRect($newGC, $hBitmap, 0, 0, $iX, $iY) _GDIPlus_ImageSaveToFile($newBmp, @ScriptDir & '\Image1.jpg') Do Until GUIGetMsg() = $GUI_EVENT_CLOSE FileClose($File) _GDIPlus_BrushDispose ($BrushBckr) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($GC) _GDIPlus_GraphicsDispose($newGC) _GDIPlus_BitmapDispose($newBmp) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Main ; _GDIPlus_GetPixel Func _GDIPlus_GetPixel($hBitmap, $X, $Y) Local $result = DllCall($ghGDIPDLL, "int", "GdipBitmapGetPixel", "ptr", $hBitmap, "int", $X, "int", $Y, "dword*", 0) If @error Then Return SetError(1, 0, 0) Return SetError($result[0], 1, $result[4]) EndFunc ;==>_GDIPlus_GetPixel
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