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:
And the result of the file . zip is the folder + the files inside:
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?
– Leandro Angelo
I did the test exactly to Gora and not... and the difference is that in Windows it gets worse than via library...
– Leonardo Bonetti
But is there any configuration to work in the best possible?
– Leonardo Bonetti
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.– Pedro Gaspar
@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.
– Leonardo Bonetti
what type/extension of files?
– Ricardo Pontual
@Ricardopunctual will always be JPEG, AI or EPS
– Leonardo Bonetti
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?
– Leandro Angelo
@Leandroangelo compression is different from resizing, I want compression
– Leonardo Bonetti
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
– Leandro Angelo
I want compression of the files inside the folder, in a general panorama, the decrease of that . zip
– Leonardo Bonetti