Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i write string on WriteableBitmap?

Tags:

silverlight

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 ?

like image 549
Yanshof Avatar asked Mar 24 '11 21:03

Yanshof


1 Answers

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();
}
like image 80
Dan Auclair Avatar answered Sep 23 '22 04:09

Dan Auclair