convert bitonal TIFF to bitonal PNG in C#

前端 未结 5 1702
天涯浪人
天涯浪人 2021-01-12 10:00

I need to convert bitonal (black and white) TIFF files into another format for display by a web browser, currently we\'re using JPGs, but the format isn\'t crucial. From rea

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 10:39

    Trying jaroslav's suggestion for color depth doesn't work:

    static void Main(string[] args)
    {
            var list = ImageCodecInfo.GetImageDecoders();
            var jpegEncoder = list[1]; // i know this is the jpeg encoder by inspection
            Bitmap bitmap = new Bitmap(500, 500);
            Graphics g = Graphics.FromImage(bitmap);
            g.DrawRectangle(new Pen(Color.Red), 10, 10, 300, 300);
            var encoderParams = new EncoderParameters();
            encoderParams.Param[0] = new EncoderParameter(Encoder.ColorDepth, 2);
            bitmap.Save(@"c:\newbitmap.jpeg", jpegEncoder, encoderParams);
    
    }
    

    The jpeg is still a full color jpeg.

    I don't think there is any support for grayscale jpeg in gdi plus. Have you tried looking in windows imaging component?

    http://www.microsoft.com/downloads/details.aspx?FamilyID=8e011506-6307-445b-b950-215def45ffffd8&displaylang=en

    code example: http://www.codeproject.com/KB/GDI-plus/windows_imaging.aspx

    wikipedia: http://en.wikipedia.org/wiki/Windows_Imaging_Component

提交回复
热议问题