For instance, here is sample JPEG which I cannot SAVE (!) but can read (e.g. find out width and height) using standard dotnet classes. Original file:
http://dl.dropbox.com/u/5079317/184809_1_original.jpg
After saving same image in windows image editor, all works great:
http://dl.dropbox.com/u/5079317/184809_1_resaved.jpg
I noticed this bug long time ago but it wasn’t major problem. But in current project I have thousands of such images and i really need some kind of solution.
Which 3rd party libraries could be used?
Here is how I am reading:
public ImageFile SaveImage(HttpPostedFileBase file, string fileNameWithPath, bool splitImage, out string errorMessage)
{
try
{
using (var stream = file.InputStream)
{
using (Image source = Image.FromStream(stream))
{
return SaveImage(source, fileNameWithPath, splitImage, out errorMessage);
// which actually do source.Save(fileNameWithPath, ImageFormat.Jpeg);
// Exception: A generic error occurred in GDI+.
}
}
}
catch (Exception e)
...
}
Resizing of original image to same size solves problem: