开发者

Parameter is not valid when saving TIFF to stream

开发者 https://www.devze.com 2023-02-22 08:19 出处:网络
I have a multi-page TIFF that I\'m splitting up page by page using Leadtools, and changing the compression on them to be compatible with a third party. When I try to save the image to a memoryStream,

I have a multi-page TIFF that I'm splitting up page by page using Leadtools, and changing the compression on them to be compatible with a third party. When I try to save the image to a memoryStream, I get a Parameter is not valid exception. However, this only happens on their machine, or my test machine running Server 2008. I cannot reproduce this on my development machine (Win 7 using VS2008). Here is the code:

              RasterImage image = codecs.Load( file, 0, CodecsLoadByteOrder.RgbOrGray, currentPage, currentPage + (detail.Pages - 1) );
              Image newImage = RasterImageConverter.ConvertToImage( image, ConvertToImageOptions.None );
              MemoryStream memStream = new MemoryStream();

              ImageCodecInfo encoderInfo = GetEncoderInfo(  );

              EncoderParameters encoderParams = new EncoderParameters( 1 );
              EncoderParameter parameter = new EncoderParameter( System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4 );
              encoderParams.Param[0] = parameter;
              newImage.Save(memStream, encoderInfo , encoderParams);
开发者_高级运维

Any thoughts on this? Thanks for the help!


Check the pixel format of the image. If it's anything other than 1 bit, this will fail - you can't use CCITT on anything other than 1 bit. It could also be that the particular OS doesn't have a CCITT4 subcodec and might only have a CCITT3 (although this is highly unlikely).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号