I have function which takes a bitmap, copies part of it and saves it as 8bpp tiff. Filename of the result image is unique and file doesn't exist, program has permission to write to the target folder.
void CropImage(Bitmap map) {
Bitmap croped = new Bitmap(200, 50);
using (Graphics g = Graphics.FromImage(croped)) {
g.DrawImage(map, new Rectangle(0, 0, 200, 50), ...);
}
var encoderParams = new EncoderParameters(2);
encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8L);
encoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionNone);
croped.Save(filename, tiffEncoder, encoderParams);
croped.Dispose();
}
Weird thing is that this funcion works well on some computers (Win 7) and throws System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI exception on other computers (mostly Win XP).
All computers have the .NET 3.5 SP1 runtime installed.
If I use croped.Save(filename, ImageFormat.Tiff);
instead croped.Save(filename, tiffEncoder, encoderParams);
than it works on all computers, but I need to save Tiff in 8bpp format.
Do you have any ideas, where the problem could be?
Thanks, Lukas