❔ How to get pixel information from WPF InkCanvas
I'm trying to get a 2d array of brightness values of each pixel (average of red, blue and green values) for whatever the user draws on the InkCanvas but I don't know how I should be getting the pixel info. How should I go about doing this?
8 Replies
you could render it into a bitmap, but i dont know how good the performance is..
That sounds right. The information is exposed as stroke data otherwise, but I think there's render math to actually get the pixels. Rendering to bmp in memory would be the easiest way
luckily, I dont care about performance for this. However i tried using a bitmap but I may have done something wrong. Through some testing I found that a lot of the values for pixels were 0 (when they should all be 255 as the canvas is completely white). Is there any metadata i need to account for? Here is the code:
that seems right, depending on margins you have on your InkCanvas. I'd have to fire up a project to see what's wrong
The margins? if those affect how this would work then that may be the issue as my inkcanvas doesn't fill the whole screen.
I think it only matters if the margins are on the InkCanvas, because then that changes size calculations. If you have padding or margins in ancestor controls it's fine
Yep, Ive got it working now thanks to that. Thank you very much for the help.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.