Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Bitmap Image from xaml control using WritableBitmapEx

How I can create bitmap image from xaml control using WritableBitmapEx. In my winRT application I need to create a snapshot of my window for implementing Pin to Tile(pinning secondary tile). I found WritableBitmap.render() is missing in winRT. How can I achieve this functionality by using WritableBitmapEx.

like image 523
StezPet Avatar asked Dec 20 '22 18:12

StezPet


1 Answers

Somehow they missed implementing WriteableBitmap.Render() and while from what I have been hearing it might come in a later version of the SDK, for now your options are to either use WriteableBitmap and populate it pixel by pixel with the content of your control, perhaps with the help of WriteableBitmapEx or alternatively use DirectX, perhaps with help of SharpDX which is a wrapper for DirectX that you can use in a C# app. You do need to use DirectX/Direct2D/DirectWrite if you want to render any text. It is not too hard to do with DirectX if your UI is simple. There is a sample that seems to be a good place to start here.

EDIT*

Then there is also a WriteableBitmap.Render() extension method I started implementing in WinRT XAML Toolkit that has a somewhat limited but potentially helpful support for rendering visual trees. I am planning to extend it to support more UI elements if necessary. It currently supports typical TextBlocks and shapes with solid color or gradient backgrounds.

EDIT 2*

Windows 8.1 adds RenderTargetBitmap.RenderAsync() API, which is quite helpful, though it has some limitations e.g. it requires the rendered UI to be part of the visual tree (though it can be in a hidden panel), misses video playback, DirectX content and I believe WebView content too.

like image 188
Filip Skakun Avatar answered May 14 '23 13:05

Filip Skakun