NEED FUNCTION FOR CONVERT IMAGE TO BYTE AND BYTE TO IMAGE.

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
C# 
C#
 1100  View(s)
Ratings:
Rate this:
Hi Expert,

How to convert image to byte and byte to image in C#?

Your help is a great appreciated.
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Need function for convert image to byte and byte to image.

    Convert image to byte:

    public static byte[] _ImageToByte(Image img)
    {
             ImageConverter converter = new ImageConverter();
             return (byte[])converter.ConvertTo(img, typeof(byte[]));
    }

    Convert Image to byte:

    public static Bitmap _ByteToImage(byte[] blob)
            {
                MemoryStream mStream = new MemoryStream();
                byte[] pData = blob;
                mStream.Write(pData, 0, Convert.ToInt32(pData.Length));
                Bitmap bm = new Bitmap(mStream, false);
                mStream.Dispose();
                return bm;
            }

  1. Manmohan Jha

    Post:35

    Points:245
    Re: Need function for convert image to byte and byte to image.

            private byte[] ReadImg2Byte(Image fileName)
            {
                try
                {
                    using (Bitmap image = new Bitmap(fileName))
                    {
                        stream = new MemoryStream();
                        image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
                return stream.ToArray();
            }


          private Image view_img()
          {
          MemoryStream stream = new MemoryStream((byte[])byteimg);
          Bitmap image = new Bitmap(stream);
          return image;
           }

    Mj

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!