0

我正在将我当前的 (Silverlight) WP8.0 应用程序移植到通用 Windows 应用程序。在这个应用程序中,我有一个控件,允许用户使用自定义拨号控件。当表盘停止时,应用程序应该从该特定点(和底层图像)获取像素颜色。

在 WP8.0 中,我曾经这样做过:

WriteableBitmap wb = new WriteableBitmap(ColorWheelImage, null);
Color c = wb.GetPixel(pointX, pointY);

ColorWheelImage 在 XAML 中。

在 WinRT 中,WriteableBitmap 仅支持new WriteableBitmap(int pixelWidth, int pixelWidth)而不像 Silverlight 中那样设置图像。

我该如何解决这个问题..我似乎无法弄清楚:(!

谢谢,尼尔斯

4

1 回答 1

3

在 WinRT 中,WriteableBitmap无法绘制视觉效果。相反,MS 添加了新控件RenderTargetBitmap

RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); 
await renderTargetBitmap.RenderAsync(ColorWheelImage, width, height);
IBuffer pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

但是GetPixelsAsync()给你IBuffer, 而不是 int 数组。要获得一个 ordinal WriteableBitmap,您可以使用WriteableBitmapEx

var width = renderTargetBitmap.PixelWidth;
var height = renderTargetBitmap.PixelHeight;
var writeableBitmap = await new WriteableBitmap(1, 1).FromPixelBuffer(pixelBuffer, width, height);
于 2014-09-01T03:43:25.280 回答