How to save a Bitonal .tiff using CompressionCCITT4

This was a pain…. There are a couple of articles that got me really close, but this one was the finisher!–use-byte-array-instead-of-writing-to-locked-image-bytes.aspx

The trick was when I was converting the C# to from this article

It mentions that you need to cast the bytes to ints

This is the salient line

pixelTotal = CInt(sourceBuffer(sourceIndex + 1)) + CInt(sourceBuffer(sourceIndex + 2)) + CInt(sourceBuffer(sourceIndex + 3))
Here is more info
Also, note that if you want to retain the resolution you need to
In the ConvertToBitonal routine add the line marked below:

// Create destination bitmap
Bitmap destination = new Bitmap(source.Width, source.Height, PixelFormat.Format1bppIndexed);

-----> destination.SetResolution(source.HorizontalResolution, source.VerticalResolution);

Leave a Reply

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

You are commenting using your 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