How to decrease the file size . zip generated by Dotnetzip?

Asked

Viewed 8,509 times

1

Using the library Dotnetzip, I am zipping a folder with two image files (can be JPEG, EPS or AI) exactly equal (for test effect), each with 7.25 MB. I get the. zip file with the size of 14.3 MB.

Apparently the compression is not being so effective, since the images are equal, the decrease should be greater, starting from the following example, there is some way to improve the compression?

using (ZipFile zip = new ZipFile())
        {
            zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; //Adicionei isso mas não surtiu efeito.
            if (Directory.Exists(Path.Combine(TempZipFiles,UniqueKey)))
                {
                    try
                    {
                      zip.AddDirectory(Path.Combine(TempZipFiles, UniqueKey), new DirectoryInfo(UniqueKey).Name);
                    }
                    catch
                    {
                        throw;
                    }
                }
            // Salva o arquivo zip para a memória
            try
            {
                byte[] buffer = new byte[16 * 1024];
                using (MemoryStream ms = new MemoryStream())
                {
                    zip.Save(ms);
                    int read;
                    while ((read = ms.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    return ms.ToArray();
                }
            }
            catch
            {
                throw;
            }
}

I don’t know if it’s related, but I’m zipping this briefcase:

inserir a descrição da imagem aqui

And the result of the file . zip is the folder + the files inside:

inserir a descrição da imagem aqui

  • You will not get a large compression of this type of file when zipping the images. Compressing by another tool or simply directly in windows, you see a big difference in file size?

  • I did the test exactly to Gora and not... and the difference is that in Windows it gets worse than via library...

  • But is there any configuration to work in the best possible?

  • I believe that the fact that the images are exactly the same does not change at all the final size of the .zip, because I imagine that the compression is done file by file. And, as commented @Leandroangelo, the files .jpg are already images compressed by nature, so you won’t get big size gains by compressing them.

  • @Pedrogaspar I get it ! I thought because the compression is through dictionaries, because the two images are the same it would compress better (like 50%), but the two images were only one example, the real scenario will be images of different sizes. Anyway I’ll wait if anyone answers anything, at least explanatory.

  • what type/extension of files?

  • @Ricardopunctual will always be JPEG, AI or EPS

  • But what do you really want? reduce the size of the files to store, without changing the originals or changing the compression and size of the actual image?

  • @Leandroangelo compression is different from resizing, I want compression

  • So... but what I asked is do you want file compression or image compression? Being from the image would result in a smaller file, but with loss of quality. If it is only from the file, it has no magic no

  • I want compression of the files inside the folder, in a general panorama, the decrease of that . zip

Show 6 more comments

1 answer

2

Although it is already debated in the comments, just to formalize, the compression of files .jpeg and .jpg (Joint Photographic Experts Group) doesn’t have much effect because this format is already a compressed image.
It would be the equivalent of compressing an already compressed file.

This site talks about the types of images, including the compressed format JPEG: https://www.infowester.com/imagens.php

Images with uncompressed formats such as BMP and TIFF, would have a good gain when they were compacted.

You can try to change the compression level for a little better gain and decrease the file size a little more. I don’t know how it works in the library you’re using, but for example the System.IO.Compression of .NET has that option: System.IO.Compression

Browser other questions tagged

You are not signed in. Login or sign up in order to post.