转换的BitmapImage以字节的Windows Phone 8.1运行时[]数组 [英] Convert BitmapImage to byte[] array in Windows Phone 8.1 Runtime

查看:164
本文介绍了转换的BitmapImage以字节的Windows Phone 8.1运行时[]数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几样要做到这一点,但他们对于Windows Phone的8.0或8.1的Silverlight。

There are a few samples to do this but they are for Windows Phone 8.0 or 8.1 Silverlight.

但你怎么能对Windows Phone的8.1运行时做到这一点?

But how can you do this for Windows Phone 8.1 Runtime?

推荐答案

您不能从Windows.UI.Xaml.Media.Imaging提取像素的 BitmapImage的

You cannot extract the pixels from a Windows.UI.Xaml.Media.Imaging.BitmapImage.

的最一般的解决方案是使用一个WriteableBitmap的代替的BitmapImage的。这些课程都是 BitmapSources 并几乎可以互换使用。该 WriteableBitmap的通过它的 PixelBuffer 属性:

The most general solution is to use a WriteableBitmap instead of a BitmapImage. These classes are both BitmapSources and can be used almost interchangeably. The WriteableBitmap provides access to its pixel data via its PixelBuffer property:

byte[] pixelArray = myWriteableBitmap.PixelBuffer.ToArray(); // convert to Array
Stream pixelStream = wb.PixelBuffer.AsStream();  // convert to stream



否则,你将需要获得来自任何地方的BitmapImage的距离得到了他们的像素。根据BitmapImage的初始化方式您可以从它的 UriSource 财产。该的WinRT XAML中工具箱拥有的扩展方法FromBitmapImage 从基于其UriSource一个BitmapImage的创建WriteableBitmap的。

Otherwise you will need to acquire the pixels from wherever the BitmapImage got them from. Depending on how the BitmapImage was initialized you may be able to find its origin from its UriSource property. The WinRT Xaml Toolkit has an extension method FromBitmapImage to create a WriteableBitmap from an BitmapImage based on its UriSource.

这是丑陋的办法是使BitmapImage的成图像,创建的 RenderTargetBitmap 基于图像,然后获取其像素RenderTargetBitmap的 CopyPixelsAsync ()

An ugly option would be to render the BitmapImage into an Image, create a RenderTargetBitmap based on the Image and then get its Pixels with RenderTargetBitmap.CopyPixelsAsync()

这篇关于转换的BitmapImage以字节的Windows Phone 8.1运行时[]数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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