TiffBitmapEncoder to encode Tiff to CCIT4

J

JamesW

Hello, .NET platform has classes to manipulate Tiffs.
I have tried to compress a picture using MSDN's sample Tiff CCIT4
but it does not seems to work. Can anyone give any help how to convert
a Tiff file to CCITT4?

Cheers!

int width = 128;
int height = width;
int stride = width / 8;
byte[] pixels = new byte[height * stride];

// Define the image palette
BitmapPalette myPalette = BitmapPalettes.Gray4;

// Creates a new empty image with the pre-defined palette

BitmapSource image = BitmapSource.Create(
width,
height,
96,
96,
PixelFormats.Indexed1,
myPalette,
pixels,
stride);

FileStream stream = new FileStream("new.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "Codec Author is: " +
encoder.CodecInfo.Author.ToString();
encoder.Compression = TiffCompressOption.Ccitt4;
encoder.Frames.Add(BitmapFrame.Create(image));
encoder.Save(stream);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top