how to make Image.Save save as a 24-bit image?
How do I get C# to force bitmap images that are saved to be saved as 24-bit images as can be seen when you get the right-click properties of the image in Windows. All the images I save are set to 32-bit. I tried the below code with no luck. The source images are all 24-bit as well but are always saved as 32-bit images.
ImageCodecInfo bmpCodec = FindEncoder(ImageFormat.Bmp);
EncoderParameters parameters = new EncoderParameters();
parameters.Param[0] = new EncoderParameter(Encoder.ColorDepth, 24);
imgCheque.Save(DestinationFile.ToString(), bmpCodec, parameters);
The images have to be properly 24 bit as the are read by a different program that can't handle 32-bit images.
Thanks in advance,
Soult开发者_如何学编程ech
Is this any use?
// imgCheque source created somewhere else up here
using (Bitmap blankImage = new Bitmap(imgCheque.Width, imgCheque.Height, PixelFormat.Format24bppRgb))
{
using (Graphics g = Graphics.FromImage(blankImage))
{
g.DrawImageUnscaledAndClipped(imgCheque, new Rectangle(Point.Empty, imgCheque.Size));
}
ImageCodecInfo bmpCodec = FindEncoder(ImageFormat.Bmp);
blankImage.Save(@"C:\TEMP\output.bmp", bmpCodec, null);
}
Try this?
ImageCodecInfo bmpCodec = FindEncoder(ImageFormat.Bmp);
EncoderParameters parameters = new EncoderParameters();
parameters.Param[0] = new EncoderParameter(Encoder.ColorDepth, 24L);
imgCheque.Save(DestinationFile.ToString(), bmpCodec, parameters);
精彩评论