adBrite

Your Ad Here

music

BidVertiser

Friday, October 15, 2010

Converting a bitmap to a byte array

// Bitmap bytes have to be created via a direct memory copy of the bitmap
private byte[] BmpToBytes_MemStream (Bitmap bmp)
{
 MemoryStream ms = new MemoryStream();
 // Save to memory using the Jpeg format
 bmp.Save (ms, ImageFormat.Jpeg);
 
 // read to end
 byte[] bmpBytes = ms.GetBuffer();
 bmp.Dispose();
 ms.Close();

 return bmpBytes;
}
 //Bitmap bytes have to be created using Image.Save()
private Image BytesToImg (byte[] bmpBytes)
{
 MemoryStream ms = new MemoryStream(bmpBytes);
 Image img = Image.FromStream(ms);
 // Do NOT close the stream!
 
 return img;
}

No comments:

Post a Comment

clicksor

Go Daddy Girl Ella Koon- $7.49 .COM Domains
CompUSA