如何在WinRT中绘制字符串到位图图像

本文关键字:字符串 位图 图像 绘制 WinRT | 更新日期: 2023-09-27 17:49:22

如何在winRT中为图像绘制字符串?在WinForms中,可以使用drawstring()方法在system.drawing命名空间内完成,但我无法在WinRT API中找到等效的

如何在WinRT中绘制字符串到位图图像

在Windows 8.1中,他们终于支持将XAML控件呈现为位图。现在可以使用

var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(uiElement, width, height));
var buffer = await renderTargetBitmap.GetPixelsAsync();
var tmpWbm = new WriteableBitmap(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight);

你将不得不使用DirectX。你可以在c#中使用SharpDx。

Direct2D是WinRT中GDI的替代品。所以你必须使用c++/CX和DirectX来绘制文本。

我没有任何例子给你,但也许这个链接(以及包含的链接)可以帮助你。

你不能-不幸的是没有这样的API:-(

Google搜索"Metro CSharp使用Direct2D和DirectWrite for Graphics"。这是他们的代码示例之一。这不是我见过的最简洁的例子,但它确实有效。使用SharpDX做同样的事情会更简洁。