The selection of compression method under WinForm

Source: Internet
Author: User
Tags rar

1. Selection of compression types

Compression is divided into lossy compression and lossless compression, depending on the compression method. One kind of MP3 files in a certain degree of lossy compression, the human perception is not very obvious and the MP3 file volume is relatively reduced. Lossless compression is similar to zip,Rar A class of compression method, through the dictionary to save duplicate values and a certain coordinate mapping method to set corresponding values, such as repeating string accounted for 20 bit, and the mapped string only accounts for 2 bits, so it achieves the purpose of compression, the compression rate is to see the probability of the recurrence of the occurrence of the value. This is just one way to compress, and there are many compression algorithms specifically for specific files.

2.7zCompression

7-zip    Open source   software. Most of the source code is based on the release under license agreement. AES  code based on   Span style= "Font-family:verdana;" >bsd  release under license. UNRAR  Span style= "Font-family:verdana;" >GNU LGPL&NBSP, and   restricted license. For more information on licensing, see: 7-zip  license .

You can use 7-zip on any computer , including computers that are used for commercial purposes, and do not donate or pay 7-zip without prejudice to your use.

Let 's Compare the 7-zip with the usual compression software.

Software name

Mozilla Firefox

Google Earth

161 Files
15,684,168 bytes

In a single file
23,530,652 bytes

After compression

Compression ratio

After compression

Compression ratio

7-zip 4.23(7z format)

4621135

100%

6109183

100%

WinRAR 3.50

5021556

109%

6824892

112%

CABARC 5.1

5131393

111%

7434325

122%

WINZIP 10.0 Beta(maximum-ppmd)

5277118

114%

8200708

134%

7-zip 4.23(Zip format)

6222627

135%

8909446

146%

WINZIP 10.0 Beta(maximum-portable)

6448666

140%

9153898

150%

The compression ratio result is determined by the size of the compressed data. typically , the 7z format using 7-zip can be smaller 30-70%than compressed archives using zip format. and the Zip format created with 7-zip is smaller than most other compression software 2-10%.

C # implementations can refer to http://www.cnblogs.com/rentiansheng/archive/2011/09/15/2177716.html

It is used in the way that C # calls the external program, so no DLLis addedand the Exe file is called directly .

3. zip compression

Zip compression is natively supported by the Windows system, but its compression rate is not very high, if the compression ratio is more sensitive to recommend directly with 7Z or rar . I use the zip in the project directly , using open source control to achieve compression capabilities.

Donetzip (http://dotnetzip.codeplex.com/) is relatively more useful than the Zip compression class and other open source methods that are in C # . This is also the reason to choose Open Source. The official website also has the API document is basically very comprehensive, but slightly some outdated, seemingly is the update is not timely, only for everybody reference.

The code is simple:

        ///<summary>        ///Compress/// </summary>        /// <param name= "Files" ></param>        /// <param name= "Zipfullname" ></param>         Public Static voidCompress (list<string> Files,stringzipfullname) {            //if (! System.IO.Directory.Exists (FolderPath))//{            //throw new Exception ("The directory does not exist!\n"); //}            //if (System.IO.File.Exists (FolderPath + "\" + zipname))//{            //throw new Exception ("that ZipFile already exists!\n"); //}
The above commented out section is to detect if a file already exists because the following code overwrites the save.
using(ZipFile zip =NewZipFile ()) {zip.comment= System.DateTime.Now.ToString ("G"); Zip. Alternateencoding=System.Text.Encoding.UTF8; Zip. Alternateencodingusage=zipoption.always; Zip. AddFiles (Files,"");//Add to root path, if not, it should replace by "Template".zip. Save (Zipfullname); } } /// <summary> ///Decompress/// </summary> /// <param name= "FolderPath" ></param> /// <param name= "Zipname" ></param> Public Static voidDecompress (stringFolderPath,stringzipname) { using(ZipFile zip =NewZipFile (FolderPath +"\\"+zipname)) {zip. Alternateencoding=System.Text.Encoding.UTF8; Zip. Alternateencodingusage=zipoption.always; Zip. Extractall (FolderPath, extractexistingfileaction.overwritesilently); } }

Description

                Zip. alternateencoding = System.Text.Encoding.UTF8;  If you want to enable encoding, then all two statements must be added, just as you must turn on the switch before adjusting the brightness.                zip. Alternateencodingusage = zipoption.always;

Reference

Http://www.baike.com/wiki/%E5%8E%8B%E7%BC%A9

http://sparanoid.com/lab/7z/

Http://www.cnblogs.com/rentiansheng/archive/2011/09/15/2177716.html

http://dotnetzip.codeplex.com/

Any questions, please reply.

The selection of compression method under WinForm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.