0

This is how I save my image(bytes) to my database and it works fine with insert and update operations:

public static byte[] ImageToBytes(Image userImage)//Get bytes of the image
{
    using (MemoryStream ms = new MemoryStream())
    using (Bitmap tempImage = new Bitmap(userImage))
    {
        tempImage.Save(ms, userImage.RawFormat); //error here System.ArgumentNullException 
        return ms.ToArray();
    }
}

I tried saving some pictures and came across with 2 images that I just can't save. They also give a "System.ArgumentNullException" even if the pictureBox has an image loaded to it.

I though it was a file size issue, but I can even save a 4 MB file(just to test). Then I saw these "attributes" in windows photo viewer and realized that maybe these "attributes" made it not savable?

An image is savable if it looks like this (its file info):

enter image description here

But an image is not savable if it looks like this (its file info):

enter image description here

The files that were not savable was downloaded from Gmail.

Of course I can just take a screenshot on my image and the specific attributes will just be gone and I can now save it to the database. I am just asking this because I'm just curious and I have not found any similar problem/solution about this matter. And it might be a hassle if clients will have to deal with this "screenshot" workaround.

paraJdox1
  • 805
  • 9
  • 23

0 Answers0