使用 WritableBitmapEx 从 xaml 控件创建位图图像 [英] Creating Bitmap Image from xaml control using WritableBitmapEx

查看:24
本文介绍了使用 WritableBitmapEx 从 xaml 控件创建位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 WritableBitmapEx 从 xaml 控件创建位图图像.在我的 winRT 应用程序中,我需要创建我的窗口的快照以实现 Pin to Tile(固定辅助磁贴).我发现 WritableBitmap.render() 在 winRT 中丢失.如何使用 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.

推荐答案

不知何故,他们错过了实现 WriteableBitmap.Render() 而据我所知,它可能会出现在更高版本的 SDK 中,目前您的选择是使用 WriteableBitmap 并使用控件的内容逐个像素地填充它,也许在 WriteableBitmapEx 或者使用 DirectX,也许在 SharpDX 的帮助下,它是 DirectX 的包装器,您可以在 C# 应用程序中使用.如果你想渲染任何文本,你确实需要使用 DirectX/Direct2D/DirectWrite.如果您的 UI 很简单,那么使用 DirectX 并不难.在此处,有一个示例似乎是一个很好的起点.

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.

编辑*

然后还有一个WriteableBitmap.Render()扩展方法我开始在 WinRT XAML Toolkit 中实现,它对渲染视觉效果有一定的限制但可能有帮助树木.如有必要,我计划扩展它以支持更多 UI 元素.它目前支持具有纯色或渐变背景的典型 TextBlock 和形状.

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.

编辑 2*

Windows 8.1 添加了 RenderTargetBitmap.RenderAsync() API,这是非常有用的,尽管它有一些限制,例如它要求渲染的 UI 成为可视化树的一部分(尽管它可以在隐藏面板中),错过视频播放、DirectX 内容,我相信 WebView 内容也是如此.

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.

这篇关于使用 WritableBitmapEx 从 xaml 控件创建位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆