Need C# function to convert grayscale TIFF to black & white (monochrome/1BPP) TIFF

前端 未结 7 1786
清歌不尽
清歌不尽 2021-01-14 09:18

I need a C# function that will take a Byte[] of an 8 bit grayscale TIFF, and return a Byte[] of a 1 bit (black & white) TIFF.

I\'m fairly new to working with TIF

7条回答
  •  自闭症患者
    2021-01-14 09:41

    First, you would need to know how an X,Y pixel location maps to an index value in you array. This will depend upon how your Byte[] was constructed. You need to know the details of your image format - for example, what is the stride?

    I don't see 8 bit grayscale TIFF in the PixelFormat enumeration. If it was there, it would tell you what you need to know.

    Then, iterate through each pixel and look at its color value. You need to decide on a threshold value - if the color of the pixel is above the threshold, make the new color white; otherwise, make it black.

    If you want to simulate grayscale shading with 1BPP, you could look at more advanced techniques, such as dithering.

提交回复
热议问题