Bug 29836 - Image.Save() to TIFF using LZW compression results in uncompressed file
Summary: Image.Save() to TIFF using LZW compression results in uncompressed file
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Drawing ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-05-07 09:53 UTC by Dan Jarvis
Modified: 2015-05-07 09:53 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 29836 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Dan Jarvis 2015-05-07 09:53:45 UTC
Creating a Bitmap object and then saving it as a TIFF image to disk has different results running Mono on Windows versus Mono on Linux.

The following code creates a Bitmap object draws some lines on it, and forces LZW compression to save it to a file:

            Image b = new Bitmap(1000, 1000);

            Pen blackPen = new Pen(Color.Black, 3);
            int x1 = 100;
            int y1 = 100;
            int x2 = 500;
            int y2 = 100;

            using (var graphics = Graphics.FromImage(b))
            {
                int y = 900;
                for (var x = 100; x < 900; x+=10 )
                {
                    graphics.DrawLine(blackPen, x, 100, y, 900);
                    y -= 10;
                }
                    
            }

            // Encoder parameters for CCITT G4
            EncoderParameters eps = new EncoderParameters(1);
            eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, long)EncoderValue.CompressionLZW);
            
            ImageCodecInfo[] ie = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo tiffEncoder = null;
            for (int i = 0; i < ie.Length; i++)
            {
                Console.WriteLine("Encoder: " + ie[i].MimeType);
                if (ie[i].MimeType == "image/tiff")
                {
                    tiffEncoder = ie[i];
                    break;
                }
            }

            var filename = "output.tif";
            if (System.IO.File.Exists(filename)) System.IO.File.Delete(filename);
            b.Save(filename, tiffEncoder, eps);
            
            var fileInfo = new FileInfo(filename);
            Console.WriteLine("Size of " + filename + " is " + fileInfo.Length);


The result running on Windows is a file with a size of 56380 bytes and is LZW compressed.  On linux using the latest libgdiplus, the file size is 4000154 bytes and is uncompressed.