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

Sab*_*wan 7 iphone image stream uiimage xamarin.ios

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

所以我用过

    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 );
        }              
    }
Run Code Online (Sandbox Code Playgroud)

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

Dim*_*kos 29

你的代码错了.您正在读取空的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);
}
Run Code Online (Sandbox Code Playgroud)