As I know, a jpeg file has a better compression ratio between other image extensions, and if I fix it, we won’t be able to compress the jpeg file because it is the best compression, so please help me about it. I create several jpegs as follows:
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo ici = null; foreach(ImageCodecInfo codec in codecs) { if(codec.MimeType == "image/jpeg") ici = codec; } EncoderParameters ep = new EncoderParameters(); ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, _quality); using(MemoryStream ms = new MemoryStream()) { Bitmap capture = GetImage(); capture.Save(ms, ici, ep); }
And I fixed them with sharpziplib, on average each jpeg size is 130 KB and after zip each file is compressed to 70 KB, how is this possible? there are only 2 answers that I can imagine.
1- We can compress a jpeg file with a large compression ratio for zip libraries
2- My jpeg file is not created correctly, and we can create better jpeg (with a higher degree of compression, since we can no longer compress them using zip libraries)
Does anyone know about this? if we can create the best jpegs, please help me about this.
Edit:
this is my zip code for jpegs compression:
void addnewentry(MemoryStream stream, string pass, string ZipFilePath, string entryname){ ICSharpCode.SharpZipLib.Zip.ZipFile zf = new ZipFile(ZipFilePath); if(!String.IsNullOrEmpty(pass)) zf.Password = pass; StaticDataSource sds = new StaticDataSource(Stream); zf.BeginUpdate(); zf.Add(sds, entryName); zf.CommitUpdate(); zf.IsStreamOwner = true; zf.Close(); } public class StaticDataSource : IStaticDataSource { public Stream stream { get; set; } public StaticDataSource() { this.stream.Position = 0; } public StaticDataSource(Stream stream) { this.stream = stream; this.stream.Position = 0; } public Stream GetSource() { this.stream.Position = 0; return stream; } }
source share