开发者

Discovering pixel information about a font in Silverlight

开发者 https://www.devze.com 2023-02-17 17:27 出处:网络
Let\'s say I pick some arbitrary mono-spaced font family and font size in Silverlight.Let\'s then render some string in SL using this font.Am I able to, for each character, compute the bounding box fo

Let's say I pick some arbitrary mono-spaced font family and font size in Silverlight. Let's then render some string in SL using this font. Am I able to, for each character, compute the bounding box for the character (i.e. x开发者_C百科 pixels wide, y pixels high starting at this position) and also discover whether a given pixel within the bounding box is black or white?


Rendering to a bitmap is not needed to get the size. Just add the text in a TextBlock to the UI but in an invisible way and then get the ActualWidth and ActualHeight of the TextBlock.

If you want to know whether or not a pixel will be set you will need to render the textblock to a WritableBitmap using its Render function and then test the Pixels array.

0

精彩评论

暂无评论...
验证码 换一张
取 消