Home > Uncategorized > Workaround for Bitmap ColorDepth in C#

Workaround for Bitmap ColorDepth in C#

I am almost cerain this is a bug in the .NET bitmap Codec, that you cannot change the color Depth… It always saves in its native format for Bitmap.
However, if you convert the image to a TIFF first, then it works.

Image imgTIFF = Image.FromStream(s);

ImageCodecInfo ici = GetEncoderInfo("TIFF");

EncoderParameter ep = new EncoderParameter(Encoder.ColorDepth,24L);

EncoderParameters eps =

new EncoderParameters(1);

eps.Param[0]= ep;


Image imgBMP = Image.FromFile(@"c:test.tiff");


(for reference:)


ImageCodecInfo GetEncoderInfo(string mimeType)


ImageCodecInfo[] encs = ImageCodecInfo.GetImageEncoders();

for (int ix = 0; ix <= encs.Length; ix++)


if ( encs[ix].CodecName.IndexOf(mimeType) != -1)


return encs[ix];



return null;


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: