如何在Windows Phone 8中将像素字节数组转换为位图图像 [英] How to convert pixel byte array to bitmap image in windows phone 8

查看:161
本文介绍了如何在Windows Phone 8中将像素字节数组转换为位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows Phone 8中使用像素字节绘制图像。所以我通过c ++库(c ++ / CLI)得到了一些像素字节。但是像素数据不包括位图标题。它只是像素字节数组。
是否可以将像素数据数组转换为Windows Phone中不带位图标题的位图图像?

I want to draw Image in windows phone 8 using pixel byte. so I get some pixel byte via c++ library(c++/CLI). But pixel data not include bitmap Header. It is just pixel byte array. Is this possible to convert pixel data array to bitmap Image without bitmap header in windows phone?

    public void updateImage(byte[] byteArray, UInt32 bufferSize, int cvtWidth, int cvtHeight)
    {
        // I saw this source a lot of search. But It's not work. It makes some exeption.
        BitmapImage bi = new BitmapImage();
        MemoryStream memoryStream = new MemoryStream(byteArray);
        bi.SetSource(memoryStream);

        ImageScreen.Source = bi;
    }


推荐答案

您需要使用WriteableBitmap : http:// msdn。 microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.writeablebitmap

You need to use a WriteableBitmap : http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.writeablebitmap

然后您可以访问它的PixelBuffer

Then you can access it's PixelBuffer using AsStream and save that array to the stream.

//srcWidth and srcHeight are original image size, needed
//srcData is pixel data array
WriteableBitmap wb = new WriteableBitmap(srcWidth, srcHeight); 

using (Stream stream = wb.PixelBuffer.AsStream()) 
{ 
    await stream.WriteAsync(srcData, 0, srcData.Length); 
} 

编辑

正如Proglamour在Windows Phone中说的那样,没有PixelBuffer,但是存在一个名为Pixels的属性,它是一个数组。

As Proglamour stated in WIndows Phone there is no PixelBuffer, but a property named Pixels which is an array exists.

它不能被替换,但是它是内容可以使它工作:

It cannot be replaced but it's content can so this should work:

WriteableBitmap wb = new WriteableBitmap(srcWidth, srcHeight); 
Array.Copy(srcData, wb.Pixels, srcData.Length);

这篇关于如何在Windows Phone 8中将像素字节数组转换为位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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