[MonoTouch] byte array to UIImage

dermotos me at dermotos.com
Sat Oct 22 08:10:33 EDT 2011


public static byte[] ImageToByteArray(UIImage _image)
		{
			Byte[] byteArray;
			using(NSData nsImageData = _image.AsPNG())
			{
				byteArray = new Byte[nsImageData.Length];
			
System.Runtime.InteropServices.Marshal.Copy(nsImageData.Bytes,byteArray,0,Convert.ToInt32(nsImageData.Length));
			}
			
			return byteArray;
		}
		
		public static UIImage ByteArrayToImage(byte[] _imageBuffer)
		{
			if(_imageBuffer != null)
			{
				if(_imageBuffer.Length != 0)
				{
				NSData imageData = NSData.FromArray(_imageBuffer);
	    		return UIImage.LoadFromData(imageData);
				}
				else
					return new UIImage();
				
			}
			else
				return new UIImage();
		}

--
View this message in context: http://monotouch.2284126.n4.nabble.com/byte-array-to-UIImage-tp3926276p3928060.html
Sent from the MonoTouch mailing list archive at Nabble.com.


More information about the MonoTouch mailing list