Note that there are some explanatory texts on larger screens.

plurals
  1. PO.Net Image.Save changes tiff from CTTIT Fax 4 to LZW
    text
    copied!<p>When I rotate an image, .Net switches the tiff encoding. Is there a way I can keep the CCITT Fax 4 (Group 4 Fax encoding) and not have it switch to LZW? Here is how I am rotating an image on disk.</p> <pre><code>System.Drawing.Image img = System.Drawing.Image.FromFile(input); //rotate the picture by 90 degrees img.RotateFlip(RotateFlipType.Rotate90FlipNone); img.Save(input, System.Drawing.Imaging.ImageFormat.Tiff); </code></pre> <p>Thanks, Brian</p> <p>Update: Here's the code based on the articles linked to below. I wanted to add the code here for completenes. Also, I set the horizontal resolution because the bitmaps defaults to 96 DPI.</p> <pre><code>//create an object that we can use to examine an image file System.Drawing.Image img = System.Drawing.Image.FromFile(input); //rotate the picture by 90 degrees img.RotateFlip(RotateFlipType.Rotate90FlipNone); // load into a bitmap to save with proper compression Bitmap myBitmap = new Bitmap(img); myBitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution); // get the tiff codec info ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff"); // Create an Encoder object based on the GUID for the Compression parameter category System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Compression; // create encode parameters EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4); myEncoderParameters.Param[0] = myEncoderParameter; // save as a tiff myBitmap.Save(input, myImageCodecInfo, myEncoderParameters); // get encoder info for specified mime type private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for (j = 0; j &lt; encoders.Length; ++j) { if (encoders[j].MimeType == mimeType) return encoders[j]; } return null; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload