Parameter is not valid when saving TIFF to stream

纵饮孤独 提交于 2019-12-10 21:48:30

问题


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!


回答1:


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).



来源:https://stackoverflow.com/questions/5572231/parameter-is-not-valid-when-saving-tiff-to-stream

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!