Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LZW compression using C#

LZW compression using C#

Scheduled Pinned Locked Moved C#
csharpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bettie
    wrote on last edited by
    #1

    Is anyone know how or where I can get information about LZW compression using C#? Thank You bettie

    H 1 Reply Last reply
    0
    • B Bettie

      Is anyone know how or where I can get information about LZW compression using C#? Thank You bettie

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      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

      F 1 Reply Last reply
      0
      • H Heath Stewart

        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

        F Offline
        F Offline
        flipdoubt
        wrote on last edited by
        #3

        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.

        H 1 Reply Last reply
        0
        • F flipdoubt

          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.

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          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 the Encoding class, which you use with an EncodingParameter, which gets added to an EncodingParameters collection you pass when using Image.Save.

          Microsoft MVP, Visual C# My Articles

          F 1 Reply Last reply
          0
          • H Heath Stewart

            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 the Encoding class, which you use with an EncodingParameter, which gets added to an EncodingParameters collection you pass when using Image.Save.

            Microsoft MVP, Visual C# My Articles

            F Offline
            F Offline
            flipdoubt
            wrote on last edited by
            #5

            Can I show you my code? It is just one console file.

            H 1 Reply Last reply
            0
            • F flipdoubt

              Can I show you my code? It is just one console file.

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              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 an Encoder. You can then use the EncoderValue to specify the compression you want to use. If you look at the documentation for the Encoder.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

              F 1 Reply Last reply
              0
              • H Heath Stewart

                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 an Encoder. You can then use the EncoderValue to specify the compression you want to use. If you look at the documentation for the Encoder.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

                F Offline
                F Offline
                flipdoubt
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups