找传奇、传世资源到传世资源站!

图片压缩工具(源码),可不失真压缩大图片

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

不改变图片尺寸对图片进行压缩,亲测10M的图片压缩成了1M左右,图片还没有失真,真可谓无损压缩,棒棒哒
from clipboard
public frmZIpPhoto() { InitializeComponent(); } private void btnAdd_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") { txtPhotoF.Text = openFileDialog1.FileName; txtPhotoZF.Text = openFileDialog1.FileName.Replace(openFileDialog1.SafeFileName, "Z" openFileDialog1.SafeFileName); } } private void btnZip_Click(object sender, EventArgs e) { try { File.Copy(txtPhotoF.Text, txtPhotoZF.Text, true); Compression(txtPhotoZF.Text, decimal.MaxValue,txtSize.Text); MessageBox.Show("操作成功!新的文件名为:Z" openFileDialog1.SafeFileName); } catch { MessageBox.Show("操作失败!"); } } protected void Compression(string filePath, decimal vfileSize,string vZipSize) { FileInfo file = new FileInfo(filePath); // decimal fileSize = Math.Round((decimal)file.Length / 512, 1); // KB decimal fileSize = Math.Round((decimal)file.Length / 1024, 1); // KB if (fileSize > (decimal.Parse(vZipSize)) && vfileSize > fileSize) // Optimazed image shouldn't be more than 60KB { try { System.Drawing.Image originalImage = System.Drawing.Image.FromFile(filePath); Bitmap bitmap = new Bitmap(originalImage); ImageCodecInfo imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(it => it.MimeType == "image/jpeg"); EncoderParameters encoderParameters = new EncoderParameters(1); EncoderParameter encoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 30L); encoderParameters.Param[0] = encoderParameter; originalImage.Dispose(); bitmap.Save(filePath, imageCodecInfo, encoderParameters); // Override bitmap.Dispose(); vfileSize = fileSize; // More than 60KB will compression again Compression(filePath, vfileSize,vZipSize); } catch (Exception) { } finally { file = null; } } }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复