xforms-development
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XForms] Colour picker


From: Nilton Jose Rizzo
Subject: Re: [XForms] Colour picker
Date: Thu, 26 Nov 2020 01:05:27 -0300
User-agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2

On 25/11/2020 17:57, jon wrote:
So nobody wastes time on this I solved it in the end.

For anyone looking through the archives I ended up with this:



// get_x11_colour_under_cursor.c
// Return the RGB value of the pixel at position x,y

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <unistd.h>
#include <stdlib.h>

void getcolor_under_cursor(int x, int y, unsigned int* R, unsigned int* G, unsigned int *B)
{
        XColor c;
        static Display *d = NULL;
        XImage *image;

        if (d==NULL)
        {
                d=XOpenDisplay((char *) NULL);
                if (d==NULL)
                        exit(1);
        }

        image = XGetImage (d, XRootWindow (d, XDefaultScreen (d)), x, y, 1, 1, AllPlanes, XYPixmap);
        c.pixel = XGetPixel (image, 0, 0);
        XFree (image);
        XQueryColor (d, XDefaultColormap(d, XDefaultScreen (d)), &c);
        *R=c.red/256;
        *G=c.green/256;
        *B=c.blue/256;
}


Thankx you for sharing your solution.
TIA
--

===========================
==== Nilton José Rizzo ====
== Engenheiro Eletrônico ==
= http://www.rizzo.eng.br =
===========================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]