I have a function that takes a bitmap, copies part of it, and saves it as an 8bpp tiff. The name of the result image file is unique and the file does not exist, the program has write permission 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(); }
It is strange that this function works well on some computers (Win 7) and generates a System.Runtime.InteropServices.ExternalException: A general error occurred in the GDI exception on other computers (mainly Win XP).
All computers have the .NET 3.5 SP1 runtime installed.
If I use croped.Save(filename, ImageFormat.Tiff); instead of 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 might be?
Thanks Lucas
source share