Bitmap.Save() does crash very often on Saving jpg's. It seems to dislike
pictures on a random basis, but when it dislikes a picture there is no way
around it.
Take for example the picture
http://home.foni.net/~sjost/fremd/IMGP5753-2.JPG
I load the picture, and save it rotated by 270 degree. Works like charm:
[Test] public void Rotate270AndSaveTest()
{
ImageCodecInfo jpegCodec = null;
foreach (ImageCodecInfo c in ImageCodecInfo.GetImageEncoders())
{
if (c.MimeType == "image/jpeg")
{
jpegCodec = c;
break;
}
}
Image Picture =
Image.FromFile(@"\pwSam\2004\Bilder\BildTests\IMGP 5753-2.JPG");
EncoderParameters EncParms = new EncoderParameters(1);
EncParms.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Tr ansformation,
(long)EncoderValue.TransformRotate270);
Picture.Save(@"\pwSam\2004\Bilder\BildTests\IMGP57 53-2-Rotate270.JPG",
jpegCodec, EncParms);
}
on the other hand, I load the same picture, save and rotate it 90 degree,
and Save crashes with some fancy error message:
[Test] public void Rotate90AndSaveTest()
{
ImageCodecInfo jpegCodec = null;
foreach (ImageCodecInfo c in ImageCodecInfo.GetImageEncoders())
{
if (c.MimeType == "image/jpeg")
{
jpegCodec = c;
break;
}
}
Image Picture =
Image.FromFile(@"\pwSam\2004\Bilder\BildTests\IMGP 5753-2.JPG");
EncoderParameters EncParms = new EncoderParameters(1);
EncParms.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.Tr ansformation,
(long)EncoderValue.TransformRotate90);
Picture.Save(@"\pwSam\2004\Bilder\BildTests\IMGP57 53-2-Rotate90.JPG",
jpegCodec, EncParms);
}
TestCase 'Sam.Tests.BildTests.Rotate90AndSaveTest' failed:
System.ArgumentException : Ungültiger Parameter verwendet.
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams)
c:\pwsam\2004\sam.tests\bildtests.cs(143,0): at
Sam.Tests.BildTests.Rotate90AndSaveTest()
This does happen with all kinds of pictures, mostly pictures coming directly
from my digital kamera (Pentax *istD). Some work, some dont.
it is very annoying and makes it nearly impossible to write an app to work
with my pictures!
Anybody can help here? Can I somehow find what causes these errors, or find
a way to stop them?
thanks!!!!
Sam