C# Bitmap <--> byte[] Converstion


SUBMITTED BY: Guest

DATE: July 5, 2013, 7:39 a.m.

FORMAT: Text only

SIZE: 475 Bytes

HITS: 980

  1. public static class BitmapConverter
  2. {
  3. public static Bitmap Bytes2Bitmap(this byte[] rawImage)
  4. {
  5. MemoryStream str = new MemoryStream(rawImage);
  6. return Bitmap.FromStream(str, true) as Bitmap;
  7. }
  8. public static byte[] Bitmap2Bytes(this Bitmap bitmap)
  9. {
  10. return (byte[])TypeDescriptor.GetConverter(bitmap).ConvertTo(bitmap, typeof(byte[]));
  11. }
  12. }

comments powered by Disqus