How do I add watermark text to a bitmap in WinRT?

2019-06-27 14:54发布

问题:

I would like to do something like this http://weblogs.asp.net/broux/archive/2011/02/08/silverlight-how-to-watermark-a-writeablebitmapimage-with-a-text.aspx. I am having a tough time getting this to work in WinRT. I am using the WriteableBitmap extensions to "render" some text but I want it to look exactly like it looks in this example. Any suggestions or help?

回答1:

You could render that text to a png asset and blit it on top of the bitmap. Unless the text needs to be dynamic - then you'd need DirectWrite. WinRT XAML Toolkit has an extension method you could use to render text to a WriteableBitmap.



回答2:

This gets the job done visually:

<Grid>
    <Image Source="{Binding MyImage}" />
    <Image Source="{Binding MyWatermark}" />
</Grid>

It's certainly the same effect without all the work. If you are wanting to get it to literally make the watermark part of the original image, offloading to a service is your only current option. Without the Render() method on the WriteableBitmap there is no other option for you. Not even the XAML Toolkit solves this problem. It's a common request.

But depending on your use case, this might just be exactly what you want!

I hope it is. Best of luck.