C# UWP Get pixel color

Jorgen Sandberg 41 Reputation points
2022-08-25T07:33:10.023+00:00

Dear,

I am developing a UWP program using C# and Visual Studio 2022. I have a canvas control and want to read the color of a pixel within the canvas control. I have searched and read several replies to the same question, but they use either a Bitmap, which is not within UWP, or they include some dll and use unsafe code. In addition, the replies are some years old. I am hoping for a simple straightforward way of reading the color of pixels on a canvas control. If it does not exists, please let me know.

Please, how do I get the color of any single pixel on my canvas control using the UWP and C#? If possible I want to avoid mixing with Windows Forms and using unsafe code.

Could I avoid this by keeping track of all I put onto the canvas pixel for pixel, no, since I add text for which I have no access to the color of the pixels.

Regards,
Jorgen

Developer technologies Universal Windows Platform (UWP)
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.