Skip to content

Instantly share code, notes, and snippets.

@robvanoostenrijk
Created November 17, 2014 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robvanoostenrijk/762e1735fd3253666a22 to your computer and use it in GitHub Desktop.
Save robvanoostenrijk/762e1735fd3253666a22 to your computer and use it in GitHub Desktop.
Save Bitmap as 1-bit CCITT4 compressed TIFF
public static void SaveMonochromeTIFF(Bitmap bitmap, String outputFile)
{
if (bitmap == null)
throw new ArgumentNullException("bitmap");
imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(ici => ici.MimeType == "image/tiff");
if (imageCodecInfo == null)
throw new NotSupportedException("No image codec for tiff found.")
EncoderParameters parameters = new EncoderParameters(2);
parameters.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
parameters.Param[1] = new EncoderParameter(Encoder.ColorDepth, (long)1);
image.Save(outputFile, imageCodecInfo, parameters);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment