HELP with TIFF Codec

  • Thread starter Thread starter FigureSk8r
  • Start date Start date
F

FigureSk8r

Guest
Hi, Im having an issue with the built-in tiff codec in GDI+. The tiff files Im working with must have a very specific format: 2 frames and 25 artist tags, and compressed using CCITT4. I have built a tiff-handling class where the object consists of an array of MemoryStreams of size 2 (one for the first frame one for the second), and a bunch of int, short, and string arrays for the artist tags.

The problem is this: when I populate the MemoryStreams in the constructor, the codec used to decode/encode the tiff image seems to distort the image. I can tell because when I save the images later on, the XResolution and YResolution tags of the second frame are skewed. Also, when comparing the hex dump for the original tiff image and the copy made through my class, the hex values for the actual images start out as identical, but then at an arbitrary point in the image, the hex values are no longer consistent. Because this is a direct copy, the hex values should not be changing.

Here is the code I use to populate the MemoryStream Array (called _frames)

private void SplitFrames(Image _tiffImage)
{
ImageCodecInfo codec = GetImageCodec("image/tiff");
EncoderParameters ep = new EncoderParameters(1);
ep.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4);

FrameDimension frameDimension = new FrameDimension(_tiffImage.FrameDimensionsList[0]);

int frameCount = _tiffImage.GetFrameCount(frameDimension);
if (frameCount != 2)
throw new Exception("Invalid tiff file: Incorrect frame count.");

_frames = new MemoryStream[2];

for (int i = 0; i < frameCount; i++)
{
_frames = new MemoryStream();

_tiffImage.SelectActiveFrame(frameDimension, i);

_tiffImage.Save(_frames, codec, ep);
}
}

So the memory streams are initially populated with the variant hex values, which creates errors later on. Why does the hex dump of the image not match the original only part-way through? What other codec could I use/what should I do to ensure the image is correctly saved into the MemoryStream?

Thank you in advance!

Continue reading...
 
Back
Top