怎么把一个Image对象按指定(字节)大小压缩? 怎么把一个Image对象按指定(字节)大小压缩?....把图片按指定大小压缩或者指定比例压缩.........压缩图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 refer:http://blog.csdn.net/chinacsharper/article/details/9865491 怎么感觉好复杂啊亲,有没有这样的方法?只要传一个Image对象和压缩比率然后返回一个Image? 世界上不是所有事情都那么简单的。呃...那只有那样子了吗?是滴,赶紧结贴给分吧。这种方法会对造成明显的图像质量损失。如果你的图片对于图像压缩后质量要求很高的话。可以去研究一下图像压缩算法。我记得mepgFF也有提供对图片流进行压缩的方法。图像压缩比较底层,在c#中压缩难度很大,我看见有高人做过一个软件,可以将10m的jpg无损压缩到1m。我做kinect之前也研究过一段时间的图像压缩。最后也只能用类似楼上的方法。使用微软提供的封装进行图像压缩。 世界上不是所有事情都那么简单的。为什么不可以?稍微改一下就可以了public static bool MyYs(ref Image img,int flag) { Image iSource = img; ImageFormat tFormat = iSource.RawFormat; EncoderParameters ep = new EncoderParameters(); long[] qy = new long[1]; qy[0] = flag;//设置压缩的比例1-100 EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy); ep.Param[0] = eParam; MemoryStream ms = new MemoryStream(); try { ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo jpegICIinfo = null; for (int x = 0; x < arrayICI.Length; x++) { if (arrayICI[x].FormatDescription.Equals("JPEG")) { jpegICIinfo = arrayICI[x]; break; } } if (jpegICIinfo != null) { iSource.Save(ms, jpegICIinfo, ep); } else { iSource.Save(ms,tFormat); //iSource.Save(outPath, tFormat); } img = Image.FromStream(ms); return true; } catch { return false; } } 世界上不是所有事情都那么简单的。为什么不可以?稍微改一下就可以了public static bool MyYs(ref Image img,int flag) { Image iSource = img; ImageFormat tFormat = iSource.RawFormat; EncoderParameters ep = new EncoderParameters(); long[] qy = new long[1]; qy[0] = flag;//设置压缩的比例1-100 EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy); ep.Param[0] = eParam; MemoryStream ms = new MemoryStream(); try { ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo jpegICIinfo = null; for (int x = 0; x < arrayICI.Length; x++) { if (arrayICI[x].FormatDescription.Equals("JPEG")) { jpegICIinfo = arrayICI[x]; break; } } if (jpegICIinfo != null) { iSource.Save(ms, jpegICIinfo, ep); } else { iSource.Save(ms,tFormat); //iSource.Save(outPath, tFormat); } img = Image.FromStream(ms); return true; } catch { return false; } }帅锅,你确信你看懂了这段代码是按比例压缩图片么? 各位大侠,这样子代码为什么在textbox输入数值后,datagridview中没选中相应的行数据,没反应???? C# Socket 通过网络远程连接 发送接收字符! 页面判断问题~~~ C#发布 关于在xtrangrid中绑定按钮列! [SQL]请帮忙分析一SQL语句写法,详见帖子 如何在VC2005中使用DirectX 简单的SQL存储过程语句问题。。达人乱入。。 关于Winform(C#)窗体间传递数据的问题.谢谢! 如何在IE中嵌入一个ActiveX Form ? 如何积累CSDN下载分数、我的都用光了 以前做b/s 刚学遇到Thread问题 测试你是不是高手
是滴,赶紧结贴给分吧。
这种方法会对造成明显的图像质量损失。
如果你的图片对于图像压缩后质量要求很高的话。可以去研究一下图像压缩算法。我记得mepgFF也有提供对图片流进行压缩的方法。
图像压缩比较底层,在c#中压缩难度很大,我看见有高人做过一个软件,可以将10m的jpg无损压缩到1m。
我做kinect之前也研究过一段时间的图像压缩。最后也只能用类似楼上的方法。使用微软提供的封装进行图像压缩。
{
Image iSource = img;
ImageFormat tFormat = iSource.RawFormat;
EncoderParameters ep = new EncoderParameters();
long[] qy = new long[1];
qy[0] = flag;//设置压缩的比例1-100
EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);
ep.Param[0] = eParam;
MemoryStream ms = new MemoryStream();
try
{
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpegICIinfo = null;
for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICIinfo = arrayICI[x];
break;
}
}
if (jpegICIinfo != null)
{
iSource.Save(ms, jpegICIinfo, ep);
}
else
{
iSource.Save(ms,tFormat);
//iSource.Save(outPath, tFormat);
}
img = Image.FromStream(ms);
return true;
}
catch
{
return false;
}
}
{
Image iSource = img;
ImageFormat tFormat = iSource.RawFormat;
EncoderParameters ep = new EncoderParameters();
long[] qy = new long[1];
qy[0] = flag;//设置压缩的比例1-100
EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);
ep.Param[0] = eParam;
MemoryStream ms = new MemoryStream();
try
{
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpegICIinfo = null;
for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICIinfo = arrayICI[x];
break;
}
}
if (jpegICIinfo != null)
{
iSource.Save(ms, jpegICIinfo, ep);
}
else
{
iSource.Save(ms,tFormat);
//iSource.Save(outPath, tFormat);
}
img = Image.FromStream(ms);
return true;
}
catch
{
return false;
}
}
帅锅,你确信你看懂了这段代码是按比例压缩图片么?