Kyme Posted March 17, 2009 Share Posted March 17, 2009 hey guys i have try this out and i have stuck on this part,how i can invert color from one jpg file or some other image filefor ex#include <ScreenCapture.au3> WinActivate("SRO_Client","") Sleep(500) _ScreenCapture_Capture(@ScriptDir & "\done.jpg",0,0, 500,500)can anybody give me some clue or something...i have saw that method with RGB from here but i don't have any ideea how to apply in my case:|wait feedbacks,tnxRegards,Kyme Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 17, 2009 Share Posted March 17, 2009 (edited) I just came up with this, and I'm still working on it... I know it may be newbish.. but hey, It's a learning experience... [EDIT] And 10 mins later... It's slow... but working... [/EDIT] $DC = DllCall ("user32.dll", "int", "GetDC", "hwnd", "") For $x = 0 to @DesktopWidth DrawPixel($DC,$X,200,_GetInverted($X,200)) DrawPixel($DC,$X,201,_GetInverted($X,201)) DrawPixel($DC,$X,202,_GetInverted($X,202)) Next ;StringTrimLeft(Hex( ;MsgBox(0,"",StringTrimLeft(Hex(_GetInverted(200,200)),2)) Func _GetInverted($x,$y) $Coord = StringTrimLeft(Hex(PixelGetColor($x,$y)),2) ;MsgBox(0,"",$Coord) $R = Number(255 - Dec(StringTrimRight($Coord,4))) ;MsgBox(0,"",$R) $G = Number(255 - Dec(StringMid($Coord,3,2))) ;MsgBox(0,"",$G) $B = Number(255 - Dec(StringMid($Coord,5,2))) ;MsgBox(0,"",$B ) Return $R & $G & $B EndFunc Func DrawPixel($hDC,$X,$Y,$COLOR) DllCall ("gdi32.dll", "long", "SetPixel", "long", $hDC[0], "long", $X, "long", $Y, "long", $COLOR) EndFunc Just for the record, using this method would be PAINSTAKINGLY slllloooowww.... lol It was fun figuring a little out about color conversion though... Edited March 17, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
jvanegmond Posted March 17, 2009 Share Posted March 17, 2009 BinaryBrother, check out _ColorGet.. functions in the help file. They use bit operations instead of string operations and as such are much faster. github.com/jvanegmond Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 17, 2009 Share Posted March 17, 2009 (edited) Actually Manadar I was just about to say "Manadar is the man.." and come in with the speedy version, using a UDF you created a while ago... You will need Manadar's UDF Here...expandcollapse popup#include <_PixelGetColor.au3> #include <Misc.au3> $hDll = DllOpen("gdi32.dll") $vDC = _PixelGetColor_CreateDC($hDll) $vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight,$hDll) $DC = DllCall ("user32.dll", "int", "GetDC", "hwnd", "") For $x = 0 to @DesktopWidth DrawPixel($DC,$X,200,_GetInverted($X,200)) DrawPixel($DC,$X,201,_GetInverted($X,201)) DrawPixel($DC,$X,202,_GetInverted($X,202)) DrawPixel($DC,$X,203,_GetInverted($X,203)) DrawPixel($DC,$X,204,_GetInverted($X,204)) DrawPixel($DC,$X,205,_GetInverted($X,205)) DrawPixel($DC,$X,206,_GetInverted($X,206)) DrawPixel($DC,$X,207,_GetInverted($X,207)) Next ;StringTrimLeft(Hex( ;MsgBox(0,"",StringTrimLeft(Hex(_GetInverted(200,200)),2)) Func _GetInverted($x,$y) $Coord = Hex(_PixelGetColor_GetPixel($vDC, $x,$y, $hDll)) ;$Coord = StringTrimLeft(Hex(PixelGetColor($x,$y)),2) $R = Number(255 - Dec(StringTrimRight($Coord,4))) $G = Number(255 - Dec(StringMid($Coord,3,2))) $B = Number(255 - Dec(StringMid($Coord,5,2))) Return $R & $G & $B EndFunc Func DrawPixel($hDC,$X,$Y,$COLOR) DllCall ("gdi32.dll", "long", "SetPixel", "long", $hDC[0], "long", $X, "long", $Y, "long", $COLOR) EndFunc Func OnAutoItExit() _PixelGetColor_ReleaseRegion($vRegion) _PixelGetColor_ReleaseDC($vDC,$hDll) DllClose($hDll) EndFuncI'll look into that _ColorGet function though... Edited March 17, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
jvanegmond Posted March 17, 2009 Share Posted March 17, 2009 Heh, alright. Thanks. Let me know how it works out with the color functions. Also check the source, it's cool. github.com/jvanegmond Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 17, 2009 Share Posted March 17, 2009 (edited) #include <_PixelGetColor.au3> #include <Misc.au3> #Include <Color.au3> $hDll = DllOpen("gdi32.dll") $vDC = _PixelGetColor_CreateDC($hDll) $vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight,$hDll) $DC = DllCall ("user32.dll", "int", "GetDC", "hwnd", "") For $x = 0 to @DesktopWidth For $Y = 0 To @DesktopHeight DrawPixel($DC,$X,$Y,_GetInverted($X,$Y)) Next Next Func _GetInverted($x,$y) $Colour = _PixelGetColor_GetPixel($vDC, $x,$y, $hDll) $R = Number(255 - _ColorGetRed($Colour)) $G = Number(255 - _ColorGetGreen($Colour)) $B = Number(255 - _ColorGetBlue($Colour)) Return $B & $G & $R EndFunc Func DrawPixel($hDC,$X,$Y,$COLOR) DllCall ("gdi32.dll", "long", "SetPixel", "long", $hDC[0], "long", $X, "long", $Y, "long", $COLOR) EndFunc Func OnAutoItExit() _PixelGetColor_ReleaseRegion($vRegion) _PixelGetColor_ReleaseDC($vDC,$hDll) DllClose($hDll) EndFunc Having a hard time figuring out what went wrong... Edited March 17, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
jvanegmond Posted March 17, 2009 Share Posted March 17, 2009 (edited) Actually UDF is not written as good as I wanted it to be... Rewriting that bit now. Edit: Some BGR issues.. I wrote around it a while back and I'll do it again now but better.Use function _PixelGetColor_GetPixelRaw to get decimal value out, which is just as good.So:Func _GetInverted($x,$y) $Coord = _PixelGetColor_GetPixelRaw($vDC, $x,$y, $hDll) ;$Coord = StringTrimLeft(Hex(PixelGetColor($x,200)),2) $R = Number(255 - _ColorGetRed($Coord)) $G = Number(255 - _ColorGetGreen($Coord)) $B = Number(255 - _ColorGetBlue($Coord)) ;$Test = Hex($R & $G & $ Return $R + 256 * $G + 256 * 256 * $B EndFunc Edited March 18, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 17, 2009 Share Posted March 17, 2009 (edited) I just edited the code, I was in the process of looking at that... Your AutoIt tags got fried, so I'm gonna go look at the RAW format now... Good catch Manadar, I've been looking at that formula for 20 mins, caught it on a Google search... Couldn't quite grasp it though... This final product code is working for the entire screen... I'm gonna run back, and see if I can't get it going like this guy wants it... Maybe Manadar can suggest the final fix, as I can't seem to get the screen coordinates right. But this is a little more than "some clue or something" lol, so hopefully this pointed you in a satisfiable direction... expandcollapse popup#include <_PixelGetColor.au3> #Include <Color.au3> $hDll = DllOpen("gdi32.dll") $vDC = _PixelGetColor_CreateDC($hDll) $vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,@DesktopWidth,@DesktopHeight,$hDll) $DC = DllCall ("user32.dll", "int", "GetDC", "hwnd", "") For $x = 0 to @DesktopWidth For $Y = 0 To @DesktopHeight DrawPixel($DC,$X,$Y,_GetInverted($X,$Y)) Next Next Func _GetInverted($x,$y) $Colour = _PixelGetColor_GetPixelRaw($vDC, $x,$y, $hDll) $R = Number(255 - _ColorGetRed($Colour)) $G = Number(255 - _ColorGetGreen($Colour)) $B = Number(255 - _ColorGetBlue($Colour)) ;Return $B & $G & $R Return $R + 256 * $G + 256 * 256 * $B EndFunc Func DrawPixel($hDC,$X,$Y,$COLOR) DllCall ("gdi32.dll", "long", "SetPixel", "long", $hDC[0], "long", $X, "long", $Y, "long", $COLOR) EndFunc Func OnAutoItExit() _PixelGetColor_ReleaseRegion($vRegion) _PixelGetColor_ReleaseDC($vDC,$hDll) DllClose($hDll) EndFunc ;;;;;;;;;;;; Same AutoIt Tags to keep the Edit from getting fried... Different script below... (Modified) #include <_PixelGetColor.au3> #Include <Color.au3> #include <ScreenCapture.au3> $Handle = WinGetHandle("SRO_Client") $hDll = DllOpen("gdi32.dll") $vDC = _PixelGetColor_CreateDC($hDll) WinActivate("SRO_Client") ;BlockInput(1) <---- That will block input to help keep the screen refresh from messing with the PixelDraw ;WinSetOnTop("SRO_Client","",1) <--- Helps a little more $Pos = WinGetPos("SRO_Client") $vRegion = _PixelGetColor_CaptureRegion($vDC, $Pos[0],$Pos[1],$Pos[0]+$Pos[2],$Pos[1]+$Pos[3],$hDll) $DC = DllCall ("user32.dll", "int", "GetDC", "hwnd", "") For $x = $Pos[0] to $Pos[2] For $Y = $Pos[1] To $Pos[3] DrawPixel($DC,$X,$Y,_GetInverted($X,$Y)) Next Next _ScreenCapture_CaptureWnd(@ScriptDir & "\test.jpg",$Handle) ;BlockInput(0) <--- de-activates block ;WinSetOnTop("SRO_Client","",0) <--- de-activate 'on-top' flag Func _GetInverted($x,$y) $Colour = _PixelGetColor_GetPixelRaw($vDC, $x,$y, $hDll) $R = Number(255 - _ColorGetRed($Colour)) $G = Number(255 - _ColorGetGreen($Colour)) $B = Number(255 - _ColorGetBlue($Colour)) Return $R + 256 * $G + 256 * 256 * $B EndFunc Func DrawPixel($hDC,$X,$Y,$COLOR) DllCall ("gdi32.dll", "long", "SetPixel", "long", $hDC[0], "long", $X, "long", $Y, "long", $COLOR) EndFunc Func OnAutoItExit() _PixelGetColor_ReleaseRegion($vRegion) _PixelGetColor_ReleaseDC($vDC,$hDll) DllClose($hDll) EndFunc Edited March 17, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
jvanegmond Posted March 18, 2009 Share Posted March 18, 2009 (edited) I took another look because BinaryBrother was so interested. I even updated the UDF, so download the new version before trying this out: http://www.autoitscript.com/forum/index.php?showtopic=63318Parts of source from: http://www.csharp411.com/c-getpixel-and-setpixel/expandcollapse popup#include <_PixelGetColor.au3> #Include <Color.au3> #include <ScreenCapture.au3> Dim Const $WIDTH = 200 DIm Const $HEIGTH = 200 $hDll = DllOpen("gdi32.dll") $vDC = _PixelGetColor_CreateDC() $vRegion = _PixelGetColor_CaptureRegion($vDC, 0,0,$WIDTH, $HEIGTH) $hBMP = _WinAPI_CreateCompatibleBitmap($vDC, $WIDTH, $HEIGTH) Dim $aColorInv[$WIDTH][$HEIGTH] For $x = 0 to $WIDTH-1 For $Y = 0 To $HEIGTH-1 $Color = _PixelGetColor_GetPixelRaw($vDC, $x, $y, $hDll) $aColorInv[$x][$y] = _GetInverted($Color) Next Next _WinAPI_SelectObject($vDC, $hBMP) For $x = 0 to $WIDTH-1 For $Y = 0 To $HEIGTH-1 _PixelGetColor_SetPixelRaw($vDC, $x, $y, $aColorInv[$x][$y], $hDll) Next Next _ScreenCapture_SaveImage("C:\lolwat.jpg", $hBMP) ShellExecute("C:\lolwat.jpg") Func _GetInverted($Color) $R = Number(255 - _ColorGetRed($Color)) $G = Number(255 - _ColorGetGreen($Color)) $B = Number(255 - _ColorGetBlue($Color)) ;Return $B & $G & $R Return $R + 256 * $G + 256 * 256 * $B EndFunc Func DrawPixel($hDC,$X,$Y,$COLOR) ;DllCall ("gdi32.dll", "long", "SetPixel", "long", $hDC[0], "long", $X, "long", $Y, "long", $COLOR) _PixelGetColor_SetPixelRaw($vDC, $X, $Y, $COLOR, $hDll) EndFunc Func OnAutoItExit() _PixelGetColor_ReleaseRegion($vRegion) _PixelGetColor_DeleteDC($vDC) DllClose($hDll) EndFunc Func _PixelGetColor_SetPixelRaw($iPixelGetColor_MemoryContext,$iX,$iY,$iColor, $hDll = "gdi32.dll") $iColor = DLLCall($hDll,"int","SetPixel","int",$iPixelGetColor_MemoryContext,"int",$iX,"int",$iY,"int",$iColor) Return $iColor[0] EndFunc Edited March 18, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 18, 2009 Share Posted March 18, 2009 (edited) You are truly the man Manadar. Hopefully this guy got what he needed... P.S. I've archived all these examples for future use... I have a few ideas... Edited March 18, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
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