Click here to Skip to main content
14,640,737 members
Rate this:
Please Sign up or sign in to vote.
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

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
Rate this:
Please Sign up or sign in to vote.

Solution 2

Try below if you can use Image instead of Bimap

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

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100