[英]Reduce image size imagemagic
I have tried to compress image but has no success. 我尝试压缩图像,但没有成功。
Look at my small experiment 看我的小实验
var results = new Dictionary<int, int>();
for (int i = 0; i <= 100; i++)
{
var stream = new MemoryStream();
image.Quality = i;
image.CompressionMethod = CompressionMethod.Zip;
image.Write(stream, MagickFormat.Png);
results[i] = stream.GetBuffer().Length;
stream.Flush();
}
var best = results.OrderBy(e => e.Value).First();
// the same length as for original image. quality doesn't work in this example - dictionary values are identical
Could any one point me to right direction? 有人能指出我正确的方向吗?
I have already read some details here ImageMagick: Lossless max compression for PNG? 我已经在这里阅读了一些详细信息ImageMagick:PNG的无损最大压缩?
It seems that you are using Magick.NET . 看来您正在使用Magick.NET 。 That library has a class called ImageOptimizer that can be used to lossless compress the file.
该库有一个称为ImageOptimizer的类,可用于无损压缩文件。 An example on how you could use that can be found here: https://github.com/dlemstra/Magick.NET/blob/master/Documentation/LosslessCompression.md .
有关如何使用它的示例,可以在这里找到: https : //github.com/dlemstra/Magick.NET/blob/master/Documentation/LosslessCompression.md 。
FileInfo snakewareLogo = new FileInfo(@"c:\Snakeware.png");
Console.WriteLine("Bytes before: " + snakewareLogo.Length);
ImageOptimizer optimizer = new ImageOptimizer();
optimizer.LosslessCompress(snakewareLogo);
snakewareLogo.Refresh();
Console.WriteLine("Bytes after: " + snakewareLogo.Length);
It is still possible that your file cannot be reduced in size because it is already stored with the best compression. 由于文件已经以最佳压缩率存储,因此仍然有可能无法减小文件的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.