110,533
社区成员
发帖
与我相关
我的任务
分享
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;
}
}
[/quote]
帅锅,你确信你看懂了这段代码是按比例压缩图片么?怎么感觉好复杂啊亲,有没有这样的方法?只要传一个Image对象和压缩比率然后返回一个Image? [quote=引用 1 楼 guwei4037 的回复:] refer:http://blog.csdn.net/chinacsharper/article/details/9865491
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;
}
}
自己写个压缩方法就好了。 一般做有损压缩。
怎么感觉好复杂啊亲,有没有这样的方法?只要传一个Image对象和压缩比率然后返回一个Image? [quote=引用 3 楼 yuwenge 的回复:] [quote=引用 2 楼 u010312979 的回复:] [quote=引用 1 楼 guwei4037 的回复:] refer:http://blog.csdn.net/chinacsharper/article/details/9865491
怎么感觉好复杂啊亲,有没有这样的方法?只要传一个Image对象和压缩比率然后返回一个Image? [quote=引用 2 楼 u010312979 的回复:] [quote=引用 1 楼 guwei4037 的回复:] refer:http://blog.csdn.net/chinacsharper/article/details/9865491
怎么感觉好复杂啊亲,有没有这样的方法?只要传一个Image对象和压缩比率然后返回一个Image? [quote=引用 1 楼 guwei4037 的回复:] refer:http://blog.csdn.net/chinacsharper/article/details/9865491
怎么感觉好复杂啊亲,有没有这样的方法?只要传一个Image对象和压缩比率然后返回一个Image? refer:http://blog.csdn.net/chinacsharper/article/details/9865491
refer:http://blog.csdn.net/chinacsharper/article/details/9865491