Jump to content

_getPixel / _paintPixel


Xenobiologist
 Share

Recommended Posts

Hi,

not very useful, but maybe for somebody ...

#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
Opt('GUICloseOnESC', 1)
Opt('GUIOnEventMode', 1)
Opt("WinTitleMatchMode", 4)

Global $shell = WinGetPos("classname=Shell_TrayWnd")
Global $gui = GUICreate("Gui", 160, 160, @DesktopWidth - 160, @DesktopHeight - 160 - $shell[3], $WS_POPUP, $WS_EX_TOPMOST)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

While 1
    $pos_X = MouseGetPos(0)
    $pos_Y = MouseGetPos(1)
    Global $colors_A = _getPixelColors($pos_X, $pos_Y, $pos_X + 150, $pos_Y + 150)
    _paintPixel($colors_A, $gui, 5, 5)
WEnd

Func _getPixelColors($start_X = 0, $start_Y = 0, $end_X = @DesktopWidth, $end_Y = @DesktopHeight)
    Local $opt = Opt('ColorMode', 1)
    Local $coord[$end_X - $start_X][$end_Y - $start_Y]
    For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            $coord[$x][$y] = PixelGetColor($x + $start_X, $y + $start_Y)
        Next
    Next
    Opt('ColorMode', $opt)
    Return $coord
EndFunc   ;==>_getPixelColors

Func _paintPixel(ByRef $coord, $handle, $start_X = 0, $start_Y = 0)
    Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle)
    For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x + $start_X, "long", $y + $start_Y, "long", $coord[$x][$y])
        Next
    Next
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0])
    Return $coord
EndFunc   ;==>_paintPixel

Func CLOSEClicked()
    Exit (0)
EndFunc   ;==>CLOSEClicked

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Really cool ! But i have problem with entering an variable as a $start_X , $start_Y, this is my code:

#include <GUIConstants.au3>
$gui=GUICreate("Gui",400,400,400,400)
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit()
        Sleep(200)
        $pos=MouseGetPos(0)
        $pos2=MouseGetPos(1)
        Global $colors_A = _getPixelColors($pos,$pos2, 150, 150)
_paintPixel($colors_A,$gui, 50, 50)
    Wend
    


Func _getPixelColors($start_X = 0, $start_Y = 0, $end_X = @DesktopWidth, $end_Y = @DesktopHeight)
    Local $opt = Opt('ColorMode', 1)
    Local $coord[$end_X - $start_X][$end_Y - $start_Y]
    For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            $coord[$x][$y] = PixelGetColor($x + $start_X, $y + $start_Y)
        Next
    Next
    Opt('ColorMode', $opt)
    Return $coord
EndFunc ;==>_getPixelColors

Func _paintPixel(ByRef $coord, $handle, $start_X = 0, $start_Y = 0)
    Local $dc
    For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle)
            DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x + $start_X, "long", $y + $start_Y, "long", $coord[$x][$y])
            DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0])
        Next
    Next
    Return $coord
EndFunc ;==>_paintPixel
Edited by Uriziel01
Link to comment
Share on other sites

HI,

the questions is what are you trying to achieve?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I want to view part of screen (150x150px) under my mouse cursor in my GUI window :)

E:\Documents and Settings\PaBloo.URIZIEL01\Moje dokumenty\pixel.au3 (20) : ==> Array variable subscript badly formatted.: 
Local $coord[$end_X - $start_X][$end_Y - $start_Y] 
Local $coord[^ ERROR
Edited by Uriziel01
Link to comment
Share on other sites

Hi,

okay I see:

Edit: Code deleted

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thank You, Very Much. Xenobiologist :)

Hi,

no problem, this might be even better for you:

Edit: Code deleted (updated above)

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Just optimization: GetDC/ReleaseDC should be outside of LOOP!!

Func _paintPixel(ByRef $coord, $handle, $start_X = 0, $start_Y = 0)
    Local $dc
    $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle)
            For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x + $start_X, "long", $y + $start_Y, "long", $coord[$x][$y])
            Next
    Next
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0])
        Return $coord
EndFunc   ;==>_paintPixel
Link to comment
Share on other sites

Hi,

yeah thanks Zedna ! Never tested that. So, this is much faster. -->

#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
Opt('GUICloseOnESC', 1)
Opt('GUIOnEventMode', 1)
Opt("WinTitleMatchMode", 4)

Global $shell = WinGetPos("classname=Shell_TrayWnd")
Global $gui = GUICreate("Gui", 160, 160, @DesktopWidth - 160, @DesktopHeight - 160 - $shell[3], $WS_POPUP, $WS_EX_TOPMOST)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

While 1
    $pos_X = MouseGetPos(0)
    $pos_Y = MouseGetPos(1)
    Global $colors_A = _getPixelColors($pos_X, $pos_Y, $pos_X + 150, $pos_Y + 150)
    _paintPixel($colors_A, $gui, 5, 5)
WEnd

Func _getPixelColors($start_X = 0, $start_Y = 0, $end_X = @DesktopWidth, $end_Y = @DesktopHeight)
    Local $opt = Opt('ColorMode', 1)
    Local $coord[$end_X - $start_X][$end_Y - $start_Y]
    For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            $coord[$x][$y] = PixelGetColor($x + $start_X, $y + $start_Y)
        Next
    Next
    Opt('ColorMode', $opt)
    Return $coord
EndFunc   ;==>_getPixelColors

Func _paintPixel(ByRef $coord, $handle, $start_X = 0, $start_Y = 0)
    Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle)
    For $x = 0 To UBound($coord, 1) - 1
        For $y = 0 To UBound($coord, 2) - 1
            DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x + $start_X, "long", $y + $start_Y, "long", $coord[$x][$y])
        Next
    Next
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0])
    Return $coord
EndFunc   ;==>_paintPixel

Func CLOSEClicked()
    Exit (0)
EndFunc   ;==>CLOSEClicked

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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