有几个示例可以执行此操作,但它们适用于 Windows Phone 8.0 或 8.1 Silverlight。
但是如何为 Windows Phone 8.1 运行时执行此操作?
最佳答案
您无法从 Windows.UI.Xaml.Media.Imaging 中提取像素。 BitmapImage .
最通用的解决方案是使用 WriteableBitmap 而不是 BitmapImage。这些类都是 BitmapSources并且几乎可以互换使用。 WriteableBitmap通过其 PixelBuffer 提供对其像素数据的访问属性:
byte[] pixelArray = myWriteableBitmap.PixelBuffer.ToArray(); // convert to Array
Stream pixelStream = wb.PixelBuffer.AsStream(); // convert to stream
否则,您将需要从 BitmapImage 从哪里获取像素。根据 BitmapImage 的初始化方式,您可以从其 UriSource 中找到它的来源。属性(property)。 WinRT Xaml Toolkit有一个 extension method FromBitmapImage根据其 UriSource 从 BitmapImage 创建 WriteableBitmap。
一个丑陋的选择是将 BitmapImage 渲染成图像,创建一个 RenderTargetBitmap基于图像,然后使用 RenderTargetBitmap 获取其像素。 CopyPixelsAsync ()
关于c# - 在 Windows Phone 8.1 运行时将 BitmapImage 转换为 byte[] 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34184855/