Color of a screen pixel: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 2: | Line 2: | ||
{{omit from|MUMPS}} |
{{omit from|MUMPS}} |
||
=={{header|Applesoft BASIC}}== |
|||
[http://en.wikipedia.org/wiki/Apple_II_graphics#Low-Resolution_.28Lo-Res.29_graphics Low-Resolution (Lo-Res) graphics] 40x48 16 colors, page 1 |
|||
<lang Applesoft BASIC>X = PDL (0) * 5 / 32 |
|||
Y = PDL (1) * 3 / 16 |
|||
COLOR= SCRN( X,Y)</lang> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
Line 19: | Line 13: | ||
<lang qbasic>color = point(x, y)</lang> |
<lang qbasic>color = point(x, y)</lang> |
||
==={{header|Applesoft BASIC}}=== |
|||
[http://en.wikipedia.org/wiki/Apple_II_graphics#Low-Resolution_.28Lo-Res.29_graphics Low-Resolution (Lo-Res) graphics] 40x48 16 colors, page 1 |
|||
<lang Applesoft BASIC>X = PDL (0) * 5 / 32 |
|||
Y = PDL (1) * 3 / 16 |
|||
COLOR= SCRN( X,Y)</lang> |
|||
==={{header|Liberty BASIC}}=== |
|||
<lang lb>'This examples requires the Windows API |
|||
Struct point, x As long, y As long |
|||
hDC = GetDC(0) |
|||
result = GetCursorPos() |
|||
Print GetPixel(hDC, point.x.struct, point.y.struct) |
|||
Call ReleaseDC 0, hDC |
|||
End |
|||
Sub ReleaseDC hWnd, hDC |
|||
CallDLL #user32,"ReleaseDC", hWnd As uLong, hDC As uLong, ret As Long |
|||
End Sub |
|||
Function GetDC(hWnd) |
|||
CallDLL #user32, "GetDC", hWnd As uLong, GetDC As uLong |
|||
End Function |
|||
Function GetCursorPos() |
|||
CallDLL #user32, "GetCursorPos", point As struct, GetCursorPos As uLong |
|||
End Function |
|||
Function GetPixel(hDC, x, y) |
|||
CallDLL #gdi32, "GetPixel", hDC As uLong, x As long, y As long, GetPixel As long |
|||
End Function</lang> |
|||
==={{header|PureBasic}}=== |
|||
Return the color used at the x,y position in the current output. If the current output has an alpha channel then the result will be a 32bit RGBA value, otherwise it will be a 24bit RGB value. The color can be split in their RGB and alpha values by using the Red(), Green(), Blue() and Alpha() functions. |
|||
<lang PureBasic>Color = Point(x, y)</lang> |
|||
To get the colour of a pixel on the screen when it is not managed by PureBasic (ie. from other programs' windows), it is necessary to use Windows API. This works only under Windows. |
|||
<lang PureBasic> |
|||
hDC = GetDC_(0) |
|||
Color = GetPixel_(hDC, x, y) |
|||
ReleaseDC_(0, hDC)</lang> |
|||
This work fine!! |
|||
<lang PureBasic>poz.point |
|||
If OpenWindow(0,0,0,100,45,"Get pixel color at cursor position",#PB_Window_MinimizeGadget) |
|||
TextGadget(0,0,0,50,12,"Red: ") |
|||
TextGadget(1,0,15,50,12,"Green: ") |
|||
TextGadget(2,0,30,50,12,"Blue: ") |
|||
TextGadget(3,50,0,50,12,"") |
|||
TextGadget(4,50,15,50,12,"") |
|||
TextGadget(5,50,30,50,12,"") |
|||
hDC = GetDC_(0) |
|||
Repeat |
|||
oldx=poz\x |
|||
oldy=poz\y |
|||
GetCursorPos_(@poz) |
|||
Color = GetPixel_(hDC, poz\x, poz\y) |
|||
If poz\x<>oldx Or poz\y<>oldy |
|||
SetGadgetText(3,Str(Red(color))) |
|||
SetGadgetText(4,Str(Green(color))) |
|||
SetGadgetText(5,Str(Blue(color))) |
|||
EndIf |
|||
event=WaitWindowEvent(200) |
|||
Until event=#PB_Event_CloseWindow |
|||
ReleaseDC_(0, hDC) |
|||
EndIf</lang> |
|||
==={{header|TI-89 BASIC}}=== |
|||
Only the graph screen can be read. |
|||
<lang ti89b>pxlTest(y, x) © returns boolean</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
{{works with|Windows}}. It uses Windows API |
{{works with|Windows}}. It uses Windows API |
||
Line 117: | Line 185: | ||
return new Robot().getPixelColor(x, y); |
return new Robot().getPixelColor(x, y); |
||
}</lang> |
}</lang> |
||
=={{header|Liberty BASIC}}== |
|||
<lang lb>'This examples requires the Windows API |
|||
Struct point, x As long, y As long |
|||
hDC = GetDC(0) |
|||
result = GetCursorPos() |
|||
Print GetPixel(hDC, point.x.struct, point.y.struct) |
|||
Call ReleaseDC 0, hDC |
|||
End |
|||
Sub ReleaseDC hWnd, hDC |
|||
CallDLL #user32,"ReleaseDC", hWnd As uLong, hDC As uLong, ret As Long |
|||
End Sub |
|||
Function GetDC(hWnd) |
|||
CallDLL #user32, "GetDC", hWnd As uLong, GetDC As uLong |
|||
End Function |
|||
Function GetCursorPos() |
|||
CallDLL #user32, "GetCursorPos", point As struct, GetCursorPos As uLong |
|||
End Function |
|||
Function GetPixel(hDC, x, y) |
|||
CallDLL #gdi32, "GetPixel", hDC As uLong, x As long, y As long, GetPixel As long |
|||
End Function</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
Line 153: | Line 194: | ||
<pre>73,61,205 |
<pre>73,61,205 |
||
-> (73 61 205)</pre> |
-> (73 61 205)</pre> |
||
=={{header|PureBasic}}== |
|||
Return the color used at the x,y position in the current output. If the current output has an alpha channel then the result will be a 32bit RGBA value, otherwise it will be a 24bit RGB value. The color can be split in their RGB and alpha values by using the Red(), Green(), Blue() and Alpha() functions. |
|||
<lang PureBasic>Color = Point(x, y)</lang> |
|||
To get the colour of a pixel on the screen when it is not managed by PureBasic (ie. from other programs' windows), it is necessary to use Windows API. This works only under Windows. |
|||
<lang PureBasic> |
|||
hDC = GetDC_(0) |
|||
Color = GetPixel_(hDC, x, y) |
|||
ReleaseDC_(0, hDC)</lang> |
|||
This work fine!! |
|||
<lang PureBasic>poz.point |
|||
If OpenWindow(0,0,0,100,45,"Get pixel color at cursor position",#PB_Window_MinimizeGadget) |
|||
TextGadget(0,0,0,50,12,"Red: ") |
|||
TextGadget(1,0,15,50,12,"Green: ") |
|||
TextGadget(2,0,30,50,12,"Blue: ") |
|||
TextGadget(3,50,0,50,12,"") |
|||
TextGadget(4,50,15,50,12,"") |
|||
TextGadget(5,50,30,50,12,"") |
|||
hDC = GetDC_(0) |
|||
Repeat |
|||
oldx=poz\x |
|||
oldy=poz\y |
|||
GetCursorPos_(@poz) |
|||
Color = GetPixel_(hDC, poz\x, poz\y) |
|||
If poz\x<>oldx Or poz\y<>oldy |
|||
SetGadgetText(3,Str(Red(color))) |
|||
SetGadgetText(4,Str(Green(color))) |
|||
SetGadgetText(5,Str(Blue(color))) |
|||
EndIf |
|||
event=WaitWindowEvent(200) |
|||
Until event=#PB_Event_CloseWindow |
|||
ReleaseDC_(0, hDC) |
|||
EndIf</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 268: | Line 272: | ||
puts [format "pixel at mouse: (%d,%d,%d)" \ |
puts [format "pixel at mouse: (%d,%d,%d)" \ |
||
{*}[getPixelAtPoint {*}[winfo pointerxy .]]]</lang> |
{*}[getPixelAtPoint {*}[winfo pointerxy .]]]</lang> |
||
=={{header|TI-89 BASIC}}== |
|||
Only the graph screen can be read. |
|||
<lang ti89b>pxlTest(y, x) © returns boolean</lang> |
|||
{{omit from|Batch File|No access to GUI functions}} |
{{omit from|Batch File|No access to GUI functions}} |