开发者

Blank image converting xaml canvas to png using RenderTargetBitmap

I want to convert a xaml canvas to a png image using c#. I used RenderTargetBitmap as described in the second post here开发者_StackOverflow. It works quite well if the xaml that's meant to be converted is displayed in a window or a page and you can actually see it on screen. But if the window is closed or hidden or the canvas isn't a child of a window / page / frame, a blank image will be generated. Does anyone know why this happens or how to make it work?


I can't be sure but it may be that WPF is saving time by not rendering anything that isn't currently on screen, therefore when you grab the bitmap from the render target for that object, it hasn't been rendered and so it is blank.

I would suggest putting it on screen for the duration of your capture and then remove it. If the object is small it may even appear and disappear in no more than a flicker.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜