Color of a screen pixel: Difference between revisions

Adding the same code using “gintro” binding to GTK3.
(Added a Color type. Fixed an error in the way to find the color (dereferencing was at the wrong place).)
(Adding the same code using “gintro” binding to GTK3.)
Line 684:
 
=={{header|Nim}}==
==={Using GTK2}===
{{libheader|GTK2}}
<lang nimNim>import gtk2, gdk2, gdk2pixbuf
 
type Color = tuple[r, g, b: byte]
Line 698 ⟶ 699:
 
echo getPixelColor(0, 0)</lang>
 
==={{Using GTK3}}===
{{libheader|gintro}}===
<lang Nim>import gintro/[gtk, gobject, gio, gdk, gdkpixbuf]
 
type Color = tuple[r, g, b: byte]
 
proc getPixelColor(x, y: int32): Color =
var pixbuf = newPixbuf(Colorspace.rgb, false, 8, 1, 1)
pixbuf = pixbufGetFromWindow(getDefaultRootWindow(), x, y, 1, 1)
result = cast[ptr Color](pixbuf.readPixels())[]
 
proc activate(app: Application) =
## Needed by GTK3.
discard
 
let app = newApplication("org.gtk.example")
connect(app, "activate", activate)
discard run(app)
 
echo getPixelColor(1500, 800)</lang>
 
=={{header|Perl}}==
Anonymous user