How can I get the colour of a pixel on canvas

Hello,

I have a Canvas and there is a picture being displayed.

I would like to get the colour of that pixel where I do a mouseDown…

I tried this but it does not seem to be working…
Dim c as Color
c = me.Graphics.Pixel(X, Y)
Window1.TextField1.Text = CStr©

The canvas is coloured black throughout and regardless where I click I keep getting varied responses of the like &h008B5674

How can I get the correct colour?

Thanks.

Lennox

The canvas doesn’t contain an image. It merely displays one and then immediately forgets what you drew (that’s why you have to draw it all over again when the canvas refreshes). Go back to the original picture to get the pixel color. Assuming you’re not scaling the image when you draw it in the canvas, and assuming you’re drawing it at (0,0):

Dim c as Color
c = theImage.Graphics.Pixel(X, Y)
1 Like

Thanks Tim,

The explanation was really appreciated “The canvas doesn’t contain an image. It merely displays one and then immediately forgets what you drew (that’s why you have to draw it all over again when the canvas refreshes).”

Just these little explanation goes a very long way, sometimes what is obvious to the experienced is what is unknown to the “novice”.

Thanks again Tim.

Lennox

1 Like