Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need the code to convert a byte array of image to bitmap image.Anybody please help
when i write code like this i got an error like Parameter is not valid

C#
private Bitmap BytesToBitmap(byte[] byteArray)
        {
                       
            Bitmap imageFile = new Bitmap(new MemoryStream(byteArray));
            return imageFile;

        }

byte array refers image.
The exception thrown in first statement
Posted
Updated 1-Jun-13 0:49am
v2

Try below if you can use Image instead of Bimap

C#
public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

C#
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
 MemoryStream ms = new MemoryStream();
 imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
 return  ms.ToArray();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900