How to Precisely Extract Color Values from a Canvas Pixel in Xojo

Hello everyone,

I’m seeking assistance on implementing a feature in Xojo: extracting the color value of a specific pixel from a canvas accurately. The key is to allow users to see in real-time the color they have selected during mouse movement before clicking. I’m wondering if there is a similar implementation, like the color picker in Scratch, that I can reference or use in Xojo.

I would greatly appreciate any guidance or suggestions on how to achieve this functionality in Xojo. Thank you!

This is built-in to the color selector tool on a Mac.
What OS are you using?

If it is Windows, you can emulate this by having a picture in memory.
When you move the mous over the canvas, get the x,y co-ordinates
From the picture, use,y) to get the color.

The magnifying effect can be a second canvas, drawing the area around the mouse from the picture, but bigger.


On macOS you also have to contend with color profiles. The color that is drawn on the screen is affected by the profile that the user has set for their screen.

You’ll want to look at RGBSurface.Pixel. Draw the contents of the Canvas to a Picture object, then you can access the pixel’s color value using picture.RGBSurface.Pixel( x, y ).

EDIT: For some reason Jeff’s reply didn’t even show up for me at first. Weird.

Also note: I find Picture.RGBSurface.pixel() very unreliable in Windows 64bit builds, often giving black or completely the wrong color.
Works in 32bit.

When it fails, picture.graphic.Pixel() usually works, but is slower in bulk.

I couldn’t find an Issue report about that. Have you made one?