Byte[] to Bitmap in

Creating byte array from a file:

        String aFile = @”C:\\TEST\\chapter-ex_muji-t-shirt.jpg”;
        Byte[] bytes = null;

        FileStream fileStream = new FileStream(aFile, FileMode.Open, FileAccess.Read);
        bytes = new byte[(int)fileStream.Length];
        fileStream.Read(bytes, 0, (int)fileStream.Length);

using the above code, you can convert a file to Byte[].

Now , if you have the Byte[], you can convert that byte into bitmap,

        Bitmap thumbBitmap;
        ImageConverter ic = new ImageConverter();
        Image img = (Image)ic.ConvertFrom(bytes);

        thumbBitmap = new Bitmap(img);
        if (thumbBitmap != null)
            Response.ContentType = “image/Jpeg”;
            thumbBitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

So you can convert Byte[]  to your desired bitmap.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s