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;
imgTIFF.Save(@"c:test.tiff",ici,eps);
Image imgBMP = Image.FromFile(@"c:test.tiff");
imgBMP.Save(@"c:test.bmp");
(for reference:)
private
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
Comments (0)
Trackbacks (0)
Leave a comment
Trackback