I am trying to send images to a AS-400 and it only accepts TIFF images. I am converting them but then it is complaining that
The error is complaining about "unrecognized tiff tags..." the first two are 317 & 531 Also: "For error codes X'8F0E' and X'8F0F', a bit pattern was detected that does not conform to the rules of the decompression algorithm. Further decompression is not possible. Verify the data integrity of the input data stream and try the request again."
I have a tiff file that works, this is the details of it:
I am using code off of MSDN that I have modified. the below code IS working, but I now need to have more than 1 parameter in the encoder.
Bitmap myBitmap;
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
// Create a Bitmap object based on a BMP file.
myBitmap = new Bitmap(@"f:\testFromBlob.jpg");
// Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff");
//do the actual work
myEncoder = Encoder.Compression;
myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder,(long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
myBitmap.Save(@"f:\resultFromDotNet.tiff", myImageCodecInfo, myEncoderParameters);
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
I am out of my depth with image files. Can anybody tell me how to do a conversion that matches the settings from my test image?
I have tried changing the bit depth to 1 as well as the compression, not sure but I think it may need both changed.
UPDATE - using Magick I am able to convert to a working format using
magick convert image01.jpg -compress Group4 tiff3.tiff
If that helps at all getting me on the right track for C# / .Net
Update 2: the above code is working but I need to know how to change multiple parameters vs just one. I think that will probably be the home run.
UPDATE 3: I have the multiple parameters working, posting it here in case it helps somebody else. Now just need to wait for the client to come in and see if this works for them!
For reference here is the link to the MS documentation
Bitmap myBitmap;
ImageCodecInfo myImageCodecInfo;
Encoder compressionEncoder;
Encoder colorDepthEncoder;
EncoderParameter compressionParameter;
EncoderParameter colorDepthParameter;
EncoderParameters myEncoderParameters;
// Create a Bitmap object based on a BMP file.
myBitmap = new Bitmap(@"f:\colorTest.jpg");
// Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff");
//do the actual work
compressionEncoder = Encoder.Compression;
myEncoderParameters = new EncoderParameters(2);
compressionParameter = new EncoderParameter(compressionEncoder,(long)EncoderValue.CompressionCCITT4);
colorDepthEncoder = Encoder.ColorDepth;
colorDepthParameter = new EncoderParameter(colorDepthEncoder, 24L); //if needed this can be removed
myEncoderParameters.Param[0] = compressionParameter;
myEncoderParameters.Param[1] = colorDepthParameter;
myBitmap.Save(@"f:\resultFromDotNet1bit.tiff", myImageCodecInfo, myEncoderParameters);
In your original code sample - instead of Encoder.ColorDepth, you would want to set the parameter Encoder.Compression to EncoderValue.CompressionCCITT4.