0

Are there any way to convert Image which is stored in MS Access to byte array using C#? Currently, I have stored my Image into my database which is in byte array format. Now I want to use OleDbReader to read through my image as a byte array, but I dont know how to it.

This is my Insert image into database code:

private byte[] ConvertToDBFormat(IImage InputImage)
    {
        Bitmap BmpImage = new Bitmap(InputImage.Bitmap);
        MemoryStream MyStream = new MemoryStream();
        BmpImage.Save(MyStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] ImageAsBytes = MyStream.ToArray();
        return ImageAsBytes;
    }

This is my code where I want to read from the database as byte

byte[] buffer = (byte[])reader["FaceImage"];
5
  • 1
    And what happens with that current code? Are you able to get the byte[] correctly? (Hint: you can construct a MemoryStream from a byte[]...) Commented Aug 12, 2015 at 10:35
  • well yes i can get the byte[] correctly, but I dont really know how to convert it to image format using MemoryStream Commented Aug 12, 2015 at 10:40
  • Well have you looked at all the members of the Bitmap class, such as the Bitmap(Stream) constructor? Commented Aug 12, 2015 at 10:41
  • 1
    stackoverflow.com/questions/9173904/… Commented Aug 12, 2015 at 10:41
  • simply use it to get the image: Image.FromStream(new MemoryStream(buffer)); Commented Aug 12, 2015 at 10:42

1 Answer 1

0

You can convert the byte[] to a Bitmap using MemoryStream like this:

private Bitmap ConvertToBitmapFormat(byte[] buffer)
    {
        MemoryStream stream = new MemoryStream(buffer);
        Bitmap image = new Bitmap(stream, false);
        return image;
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.