tags:

views:

342

answers:

2

Hi All,

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,

Soultech

+1  A: 

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);
        }
fallenidol
A: 

Perhaps this may help:

link text