views:

168

answers:

1

Hello All,

I am resizing images with C#/GDI+ using the following routing

        bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
        Graphics g = Graphics.FromImage(bmpOut);
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
        g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
        g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);

and encoding it with the highest quality.

System.Drawing.Imaging.Encoder qualityEncoder = System.Drawing.Imaging.Encoder.Quality;
            EncoderParameter myEncoderParameter = new EncoderParameter(qualityEncoder, 100L);

However, the images that I get have significant loss of color (I am using JPG images only). The quality is perfect, but color is washed away. Do you have any idea what is goingf on?

Thanks a lot in advance.

A: 

See http://stackoverflow.com/questions/745610/how-to-disable-subsampling-with-net-gdi

The problem is that GDI+'s jpeg encoder doesn't allow chroma subsampling to be disabled, so color information is saved at half resolution. The only workaround may be to use a different encoder, such as ImageMagick which was suggested as an answer to the above.

David