LZW compression using C#
-
Is anyone know how or where I can get information about LZW compression using C#? Thank You bettie
See http://datacompression.info[^]. If you're just looking for a general LZH implementation like ZIP, see a good, free assembly at http://icsharpcode.com/OpenSource/SharpZipLib/Default.aspx[^]. Support for compression will be added to the .NET FCL in .NET 2.0.
Microsoft MVP, Visual C# My Articles
-
See http://datacompression.info[^]. If you're just looking for a general LZH implementation like ZIP, see a good, free assembly at http://icsharpcode.com/OpenSource/SharpZipLib/Default.aspx[^]. Support for compression will be added to the .NET FCL in .NET 2.0.
Microsoft MVP, Visual C# My Articles
Hi, guys. I have a slightly related question about compression. I've been banging out some code that uses the Imaging namespace's EncoderParameters to save an image as a multipage TIF. My problem is that the default compression schema appears to be LZW; or, at least, that is what some of my property readers are telling me. Anyway, I'm trying to save a multipage TIF with CCIT Group 4 Compression, but I get "invalid paramter" exception any time I try to add compression parameters. Heath, do you have any experience with saving multipage TIFs with CCIT Group 4 compression in GDI+? If not, do you know anyone who does? I can post my code, if you're interested.
-
Hi, guys. I have a slightly related question about compression. I've been banging out some code that uses the Imaging namespace's EncoderParameters to save an image as a multipage TIF. My problem is that the default compression schema appears to be LZW; or, at least, that is what some of my property readers are telling me. Anyway, I'm trying to save a multipage TIF with CCIT Group 4 Compression, but I get "invalid paramter" exception any time I try to add compression parameters. Heath, do you have any experience with saving multipage TIFs with CCIT Group 4 compression in GDI+? If not, do you know anyone who does? I can post my code, if you're interested.
In order to use a different encoding, there must be an encoder installed and registered with GDI and/or GDI+ to be used. This is done by passing the
Guid
of the encoder to theEncoding
class, which you use with anEncodingParameter
, which gets added to anEncodingParameters
collection you pass when usingImage.Save
.Microsoft MVP, Visual C# My Articles
-
In order to use a different encoding, there must be an encoder installed and registered with GDI and/or GDI+ to be used. This is done by passing the
Guid
of the encoder to theEncoding
class, which you use with anEncodingParameter
, which gets added to anEncodingParameters
collection you pass when usingImage.Save
.Microsoft MVP, Visual C# My Articles
-
What would it help? The fact remains that an encoder for the compression you're trying to use must be installed correctly on your system. You can use
Encoder.Compression
to create anEncoder
. You can then use theEncoderValue
to specify the compression you want to use. If you look at the documentation for theEncoder.Compression
read-only, static property in the .NET Framework SDK, you'll even see an example of using a certain compression algorithm to save a TIFF.Microsoft MVP, Visual C# My Articles
-
What would it help? The fact remains that an encoder for the compression you're trying to use must be installed correctly on your system. You can use
Encoder.Compression
to create anEncoder
. You can then use theEncoderValue
to specify the compression you want to use. If you look at the documentation for theEncoder.Compression
read-only, static property in the .NET Framework SDK, you'll even see an example of using a certain compression algorithm to save a TIFF.Microsoft MVP, Visual C# My Articles
I know that I have the encoder installed on my machine because I can save single pages at G4 as well as multi-page tifs with the default compression, but I run into issues when I put the two together. My sample code reads a TIF file name from the app.config file, saves the first page in the file as a G4 image, saves the whole document as multipage file, but then fails when using the G4 EncoderParameter along with the save MultiFrame parameter. I'm using the same algorithm each time, just passing in addition EncoderParameters to the method. The astrices show the problem:
using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; namespace consoletest { /// /// Demonstrates my problem with multipage G4 tifs. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { string testName = System.Configuration.ConfigurationSettings.AppSettings["testName"]; string compName = "compressed.tif"; string multiName = "multi.tif"; string multiG4 = "multiG4.tif"; System.Drawing.Image original = Bitmap.FromFile( testName ); try { Image[] pages = Class1.ToImageArray( original ); Class1.ToGroup4Compressed( pages[1], compName ); Class1.ToMultiPageImage( pages, multiName ); Class1.ToMultiPageImage( pages, multiG4, Class1.GetGroup4Parameter() ); } catch( Exception e ) { System.Diagnostics.Debug.WriteLine( e ); } } /// /// Turns a multi-page image into an array of single page images. /// /// /// public static Image[] ToImageArray( Image image ) { int count = image.GetFrameCount( System.Drawing.Imaging.FrameDimension.Page ); Image[] images = new Image[ count ]; if( count > 1 ) { for( int i = 0; i < count; i++ ) { image.SelectActiveFrame( System.Drawing.Imaging.FrameDimension.Page, i ); images[ i ] = image.Clone() as Image; } } r