开发者

Show Image from Byte[] in monotouch

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

so i used

    Public static Public static UIImage GetImagefromByteArray (byte[] byteArrayI开发者_如何转开发n){
        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 .


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:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜