PotassiumLover33
PotassiumLover33
CC#
Created by PotassiumLover33 on 2/6/2023 in #help
❔ How to get pixel information from WPF InkCanvas
Yep, Ive got it working now thanks to that. Thank you very much for the help.
9 replies
CC#
Created by PotassiumLover33 on 2/6/2023 in #help
❔ How to get pixel information from WPF InkCanvas
The margins? if those affect how this would work then that may be the issue as my inkcanvas doesn't fill the whole screen.
9 replies
CC#
Created by PotassiumLover33 on 2/6/2023 in #help
❔ How to get pixel information from WPF InkCanvas
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:
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)digitCanvas.ActualWidth, (int)digitCanvas.ActualHeight, 96, 96, PixelFormats.Pbgra32);
renderBitmap.Render(digitCanvas);

int width = renderBitmap.PixelWidth;
int height = renderBitmap.PixelHeight;
int pixelValues = 4; // blue, green, red, alpha
byte[] pixels = new byte[width * height * pixelValues];
renderBitmap.CopyPixels(pixels, width * pixelValues, 0);
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)digitCanvas.ActualWidth, (int)digitCanvas.ActualHeight, 96, 96, PixelFormats.Pbgra32);
renderBitmap.Render(digitCanvas);

int width = renderBitmap.PixelWidth;
int height = renderBitmap.PixelHeight;
int pixelValues = 4; // blue, green, red, alpha
byte[] pixels = new byte[width * height * pixelValues];
renderBitmap.CopyPixels(pixels, width * pixelValues, 0);
9 replies