I have a WriteableBitmap and would like the user to be able to draw over it as if it was an simple bitmap.
How can i do it ?
You can set up a TextBlock control in code, set the Text property with the string, and call the Render() method of the WritableBitmap with that TextBlock. The TextBlock never has to be on the visual tree, but you will have to call Invalidate() on the bitmap after to get the text to show up.
private void RenderString(WriteableBitmap bitmap, string stringToRender)
{
TextBlock textBlock = new TextBlock();
textBlock.Text = stringToRender;
// set font, size, etc. on textBlock
bitmap.Render(textBlock, null);
bitmap.Invalidate();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With