Click here to Skip to main content
11,642,381 members (64,987 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi,
      I am trying to compress and decompress any type of image using C# coding.
Anybody have any idea about this plz help..
Thanks in advance.
Posted 8-Mar-12 18:47pm
Comments
SAKryukov at 9-Mar-12 0:54am
   
Do you want your own compression algorithm, your own implementation of the known algorithm or just the use of something existing in .NET? (In last case, just Google, see MSDN.)

What did you try so far? What is the problem?
--SA
Manisha Tambade at 9-Mar-12 1:05am
   
I am not implementing own algorithm.
i have tried from msdn GZipStream sample code but not working..

thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

.NET provides GZipStream class for better compression and decompression. Here is the sample code:

try
{
    string anyString = File.ReadAllText("MyImage.jpg");
    CompressStringToFile("new.gz", anyString);
}
catch
{
    // Couldn't compress.
}
}
 
public static void CompressStringToFile(string fileName, string value)
{
  string temp = Path.GetTempFileName();
  File.WriteAllText(temp, value);
  byte[] b;
  using (FileStream f = new FileStream(temp, FileMode.Open))
  {
    b = new byte[f.Length];
    f.Read(b, 0, (int)f.Length);
  }
  using (FileStream f2 = new FileStream(fileName, FileMode.Create))
  using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false))
  {
    gz.Write(b, 0, b.Length);
  }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Comments
Manisha Tambade at 9-Mar-12 4:40am
   
hi,Thanks for solution link..
In this link example,gZipStream is used and stream object is created.
here CopyTo method of stream object is used which non existing and giving error.
So i tried for any such a method like copy ,but its not there so cant run this sample..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 9 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100