从网上找的非常有效。图片3M到500k

   private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = ; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
} /// <summary>
/// 图片压缩(降低质量以减小文件的大小)
/// </summary>
/// <param name="srcBitmap">传入的Bitmap对象</param>
/// <param name="destStream">压缩后的Stream对象</param>
/// <param name="level">压缩等级,0到100,0 最差质量,100 最佳</param>
public static void Compress(Bitmap srcBitmap, Stream destStream, long level)
{
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters; // Get an ImageCodecInfo object that represents the JPEG codec.
myImageCodecInfo = GetEncoderInfo("image/jpeg"); // Create an Encoder object based on the GUID // for the Quality parameter category.
myEncoder = Encoder.Quality; // Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one // EncoderParameter object in the array.
myEncoderParameters = new EncoderParameters(); // Save the bitmap as a JPEG file with 给定的 quality level
myEncoderParameter = new EncoderParameter(myEncoder, level);
myEncoderParameters.Param[] = myEncoderParameter;
srcBitmap.Save(destStream, myImageCodecInfo, myEncoderParameters);
} /// <summary>
/// 图片压缩(降低质量以减小文件的大小)
/// </summary>
/// <param name="srcBitMap">传入的Bitmap对象</param>
/// <param name="destFile">压缩后的图片保存路径</param>
/// <param name="level">压缩等级,0到100,0 最差质量,100 最佳</param>
public static void Compress(Bitmap srcBitMap, string destFile, long level)
{
Stream s = new FileStream(destFile, FileMode.Create);
Compress(srcBitMap, s, level);
s.Close();
}

C# 如何进行图像的压缩的更多相关文章

  1. 使用方向变换(directional transform)图像分块压缩感知

    论文的思路是先介绍分块压缩感知BCS,然后介绍使用投影和硬阈值方法的迭代投影方法PL,接着将PL与维纳滤波器结合形成SPL(平滑PL),并且介绍了稀疏表示的几种基,提出了两种效果较好的稀疏基:CT与D ...

  2. 图像jpeg压缩

    图像分割 8X8 颜色空间转换RGB->YCbCr 3个8X8的矩阵 离散余弦变换:(Discrete cosine transform),简称DCT. DCT转换后的数组中第一个是一个直线数据 ...

  3. (原)调用jpeglib对图像进行压缩

    网址:http://www.cnblogs.com/darkknightzh/p/4973828.html.未经允许,严禁转载. 参考网站: http://dev.w3.org/Amaya/libjp ...

  4. swift 图像的压缩上传

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [Str ...

  5. 你想不到的压缩方法:将javascript文件压缩成PNG图像存储

    这样可以做到很高的压缩比,到底有多高,下面会提到.这种方法用到了 canvas 控件,这也意味着只有支持 canvas 控件的浏览器下才有效. 现在你可以看到,上面的图像类似一个噪声图像,但它实际上是 ...

  6. HTML5 图片本地压缩上传插件「localResizeIMG」

    移动应用中用户往往需要上传照片,但是用户上传的照片尺寸通常很大,而手机的流量却很有限,所以在上传前对图像进行压缩是很有必要的. 原生应用可以直接对文件进行处理,网页应用就没有这个优势了.不过 canv ...

  7. (转)原始图像数据和PDF中的图像数据

    比较原始图像数据和PDF中的图像数据,结果见表1.1.表1.1中各种“解码器”的解释见本文后续的“PDF支持的图像格式”部分,“PDF中的图像数据”各栏中的数据来自开源的PdfView.如果您有兴趣查 ...

  8. 【转载】VC++中的图像类型转换--使用开源CxImage类库

    一.CxImage类库简介 这只是翻译了CxImage开源项目主页上的部分简介及简单使用. CxImage类库是一个优秀的图像操作类库.它可以快捷地存取.显示.转换各种图像.有的读者可能说,有那么多优 ...

  9. 使用ajax上传图片,支持图片即时浏览,支持js图片压缩后上传给服务器

    使用ajax上传图片,支持图片即时浏览,支持js图片压缩后上传给服务器 ajax上传主要使用了 var reader = new FileReader() 此方法 js图片压缩主要是利用canvas进 ...

随机推荐

  1. smarty缓存

    huancun.php代码 <?php$p =1;if( !empty($_GET["page"])){ $p =$_GET["page"];}$file ...

  2. SQLServer 游标详解

    一.用到的数据 CREATE TABLE [dbo].[XSB]( ) NOT NULL, ) NOT NULL, [性别] [bit] NULL, [出生时间] [date] NULL, ) NUL ...

  3. python多重继承的钻石问题

    如下,我们已经有了一个从Contact类继承过来的Friend类 class ContactList(list): def search(self, name): '''Return all cont ...

  4. 剑指Offer_编程题_14

    题目描述 输入一个链表,输出该链表中倒数第k个结点. /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : va ...

  5. PubMed数据下载

    目标站点分析 目标:抓取页面中的机构名称,日期,标题,作者, 作者信息, 摘要 程序实现 # -*- coding: utf-8 -*- """ @Datetime: 2 ...

  6. MySQL数据库优化_limit_1

    转自:https://blog.csdn.net/cbjcry/article/details/70155118 1. MySQL中,在某些情况下,如果明知道查询结果只有一个,SQL语句中使用LIMI ...

  7. 【SSL】WebClient 请求 https 页面出错:未能创建 SSL/TLS 安全通道

    #问题: 当向一个https的url上发送请求,报错:未能创建 SSL/TLS 安全通道: using (WebClient client = new WebClient()) { string ad ...

  8. JAVA-Clone 对象拷贝

    JAVA 中对象的赋值是复制对象的引用,即复制引用 public static void main(String[] args) { User user = new User(1,"asds ...

  9. JAVA核心技术I---JAVA回顾

    一:基础类型运算 大部分的指令都没有支持byte.char.short,没有任何指令支持boolean类型.编译器在编译期或者运行期将byte和short类型的数据带符号扩展为相应的int类型数据,将 ...

  10. https笔记【转】

    图解HTTPS 我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取.所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议. HTTPS简介 HTTPS其实是有两部分组成:HT ...