Show image from byte [] in monochromatic

I work in a Monotouch environment in which I need to show an image that I have a 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 was looking for it, so I found out that this is an error in mono-point. reported an error , so which function can I use to display the image.

+7
source share
1 answer

Your code is incorrect. You are reading from an empty MemoryStream. UIImage.LoadFromData works fine in MonoTouch 4.0 (and since 3.2. * From what I remember). Try using the following method, you do not need a MemoryStream if you already have an image byte buffer, for example. from FileStream:

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

All Articles