Problems with this code:
It makes use of values that aren't declared or passed as values (the various textbox values).
There is no error checking at all.
It has bugs in it. I'll let you test your debugging skills. Just a quick glance over the code shows at least seven.
Momerath
Senior Poster
3,726 posts since Aug 2010
Reputation Points: 1,322
Solved Threads: 624
Skill Endorsements: 12
:)... This is not the complete project it is working fine when written in project... this is only a small part of a compressing application
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
Skill Endorsements: 1
Hmmm, I wonder ...
So if I have a textfile consisting of 26 characters, the alphabet for example, I could reduce its size by 97% of 26, being 25.22???
So I could zip all the information of the alphabet in less than 1 char?
ddanbe
Industrious Poster
4,277 posts since Oct 2008
Reputation Points: 2,121
Solved Threads: 720
Skill Endorsements: 26
That may be true, but it still has bugs in it, so it's not 'working fine'.
Momerath
Senior Poster
3,726 posts since Aug 2010
Reputation Points: 1,322
Solved Threads: 624
Skill Endorsements: 12
It is working fine with me... I have added some details You can check it now
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
Skill Endorsements: 1
@Tellalca
Yes I'm aware of the fact that a pictre with almost nothing else but blue sky can be compressed more than a picture taken on an average market place.
But I still find a compression rate of 97% very high.
ddanbe
Industrious Poster
4,277 posts since Oct 2008
Reputation Points: 2,121
Solved Threads: 720
Skill Endorsements: 26
I have used this code in the past i have the complete source which i found on either codeproject or vckicks. I have used this method to create my own image format. here is how to load and save as image using this method.
here is how to load the image
string lfile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\StrGraphic.lib";
FileStream compfile = new FileStream(FileName, FileMode.Open, FileAccess.Read);
FileStream wrt_to_decomp = new FileStream(lfile, FileMode.Create, FileAccess.Write);
StreamReader read_comp = new StreamReader(new GZipStream(compfile, CompressionMode.Decompress));
StreamWriter sw = new StreamWriter(wrt_to_decomp, Encoding.Unicode);
sw.WriteLine(read_comp.ReadToEnd());
sw.Flush();
compfile.Close();
sw.Close();
StreamReader sr = new StreamReader(lfile);
LoadedImage = new Bitmap(Image.FromStream(new MemoryStream(Convert.FromBase64String(sr.ReadToEnd()))));
Note: When opening the image file use a Stream to store the file as a byte[] array so that it can be used to save the image.
and FileName from line 2 should be replaced with the name of the image file you are opening.
Here is how to save the image
Note: When saving the image Filename from line 1 should be changed to name you are saving the image as.
private void SaveCifImage(string FileName, byte[] Data)
{
FileStream compress = new FileStream(FileName, FileMode.Create, FileAccess.Write);
StreamWriter strw = new StreamWriter(new GZipStream(compress, CompressionMode.Compress));
strw.WriteLine(Convert.ToBase64String(Data));
strw.Flush();
compress.Close();
}
Note: when using png format the compressed format will be larger than the original image
CsharpChico
Junior Poster in Training
72 posts since May 2010
Reputation Points: 12
Solved Threads: 8
Skill Endorsements: 0