在单声道显示来自Byte []的图像

时间:2023-01-24 18:07:53

I am working in Monotouch framework, in which i have to show image, what i have is byte[].

我在Monotouch框架中工作,我必须在其中显示图像,我所拥有的是byte []。

so i used

所以我用过

    Public static Public static UIImage GetImagefromByteArray (byte[] byteArrayIn){
        using (MemoryStream memStream = new MemoryStream ())
        {
            byte[] streamBytes = new byte [byteArrayIn.Length];
            memStream.Read( streamBytes, 0, byteArrayIn.Length);
            NSData data = NSData.FromArray( streamBytes );
            return UIImage.LoadFromData( data );
        }              
    }

but it always returns null, i searched for it so came to know that it is a bug in monotouch. bug reported link, so what else function may i use to show image .

但它总是返回null,我搜索它,所以才知道它是monotouch中的一个bug。错误报告链接,所以我可以用什么功能来显示图像。

1 个解决方案

#1


29  

Your code is wrong. You are reading from an empty MemoryStream. UIImage.LoadFromData works fine in MonoTouch 4.0 (and since 3.2.* from what I can remember). Try the following method, you don't need a MemoryStream if you already have the byte buffer of the image, eg. from a FileStream:

你的代码错了。您正在读取空的MemoryStream。 UIImage.LoadFromData在MonoTouch 4.0中运行良好(从我能记住的3.2。*开始)。尝试以下方法,如果您已经拥有图像的字节缓冲区,则不需要MemoryStream,例如。从FileStream:

public static UIImage GetImagefromByteArray (byte[] imageBuffer)
{
    NSData imageData = NSData.FromArray(imageBuffer);
    return UIImage.LoadFromData(imageData);
}

#1


29  

Your code is wrong. You are reading from an empty MemoryStream. UIImage.LoadFromData works fine in MonoTouch 4.0 (and since 3.2.* from what I can remember). Try the following method, you don't need a MemoryStream if you already have the byte buffer of the image, eg. from a FileStream:

你的代码错了。您正在读取空的MemoryStream。 UIImage.LoadFromData在MonoTouch 4.0中运行良好(从我能记住的3.2。*开始)。尝试以下方法,如果您已经拥有图像的字节缓冲区,则不需要MemoryStream,例如。从FileStream:

public static UIImage GetImagefromByteArray (byte[] imageBuffer)
{
    NSData imageData = NSData.FromArray(imageBuffer);
    return UIImage.LoadFromData(imageData);
}