c# Bitmap byte[]互转

c# Bitmap转byte[]

转自:http://www.cnblogs.com/liuxinls/p/3365276.html

public static byte[] Bitmap2Byte(Bitmap bitmap)
{
	using (MemoryStream stream = new MemoryStream())
	{
		bitmap.Save(stream , ImageFormat.Jpeg);
		byte[] data = new byte[stream.Length];
		stream.Seek(0 , SeekOrigin.Begin);
		stream.Read(data ,0  , Convert.ToInt32(stream.Length));
		return data;
	}
}


byte[] 转换 Bitmap

public static Bitmap BytesToBitmap(byte[] Bytes) 
{ 
	MemoryStream stream = null; 
	try 
	{ 
		stream = new MemoryStream(Bytes); 
		return new Bitmap((Image)new Bitmap(stream)); 
	} 
	catch (ArgumentNullException ex) 
	{ 
		throw ex; 
	} 
	catch (ArgumentException ex) 
	{ 
		throw ex; 
	} 
	finally 
	{ 
		stream.Close(); 
	} 
} 



你可能感兴趣的:(bitmap,byte互转,Bitmap转byte)