Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

windows 8 - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...