C# 如何进行图像的压缩
从网上找的非常有效。图片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# 如何进行图像的压缩的更多相关文章
- 使用方向变换(directional transform)图像分块压缩感知
论文的思路是先介绍分块压缩感知BCS,然后介绍使用投影和硬阈值方法的迭代投影方法PL,接着将PL与维纳滤波器结合形成SPL(平滑PL),并且介绍了稀疏表示的几种基,提出了两种效果较好的稀疏基:CT与D ...
- 图像jpeg压缩
图像分割 8X8 颜色空间转换RGB->YCbCr 3个8X8的矩阵 离散余弦变换:(Discrete cosine transform),简称DCT. DCT转换后的数组中第一个是一个直线数据 ...
- (原)调用jpeglib对图像进行压缩
网址:http://www.cnblogs.com/darkknightzh/p/4973828.html.未经允许,严禁转载. 参考网站: http://dev.w3.org/Amaya/libjp ...
- swift 图像的压缩上传
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [Str ...
- 你想不到的压缩方法:将javascript文件压缩成PNG图像存储
这样可以做到很高的压缩比,到底有多高,下面会提到.这种方法用到了 canvas 控件,这也意味着只有支持 canvas 控件的浏览器下才有效. 现在你可以看到,上面的图像类似一个噪声图像,但它实际上是 ...
- HTML5 图片本地压缩上传插件「localResizeIMG」
移动应用中用户往往需要上传照片,但是用户上传的照片尺寸通常很大,而手机的流量却很有限,所以在上传前对图像进行压缩是很有必要的. 原生应用可以直接对文件进行处理,网页应用就没有这个优势了.不过 canv ...
- (转)原始图像数据和PDF中的图像数据
比较原始图像数据和PDF中的图像数据,结果见表1.1.表1.1中各种“解码器”的解释见本文后续的“PDF支持的图像格式”部分,“PDF中的图像数据”各栏中的数据来自开源的PdfView.如果您有兴趣查 ...
- 【转载】VC++中的图像类型转换--使用开源CxImage类库
一.CxImage类库简介 这只是翻译了CxImage开源项目主页上的部分简介及简单使用. CxImage类库是一个优秀的图像操作类库.它可以快捷地存取.显示.转换各种图像.有的读者可能说,有那么多优 ...
- 使用ajax上传图片,支持图片即时浏览,支持js图片压缩后上传给服务器
使用ajax上传图片,支持图片即时浏览,支持js图片压缩后上传给服务器 ajax上传主要使用了 var reader = new FileReader() 此方法 js图片压缩主要是利用canvas进 ...
随机推荐
- IE缓存查看的方法
选择设置中的Internet选项中, 然后点击查看文件: 最终缓存目录:
- MySQL数据库服务器整体规划(思路与步骤)
MySQL数据库服务器整体规划(思路与步骤) 参考资料: http://blog.51cto.com/zhilight/1630611 我们在搭建MySQL数据库服务器的开始阶段就合理的规划,可以避免 ...
- go logs
安装导入 go get github.com/astaxie/beego/logs import "github.com/astaxie/beego/logs" 使用 packag ...
- nodeJS 调试debug
一. 用chrome来调试 1)运行node的时候,带上 --inspect-brk=9999 node --inspect-brk= index.js 2)打开chrome调试管理页面 3)如果没有 ...
- spring中获取dao或对象中方法的实例化对象
spring中获取dao的中方法的实例化对象: //获取应用上下文对象 ApplicationContext ctx = new ClassPathXmlApplicationContext(&quo ...
- springboot(二十二)spring-boot使用AOP
https://blog.csdn.net/w05980598/article/details/79053209
- Newtonsoft.Json添加项
JObject jo = (JObject)JsonConvert.DeserializeObject(result); ") { string domain=(jo["data& ...
- man termios(FreeBSD 12.0)
TERMIOS() FreeBSD Kernel Interfaces Manual TERMIOS() NAME termios - general terminal line discipline ...
- C# WinForm多线程(一)----- Thread类库
Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程.什么是进程呢?当一个程序开始运行时,它就是一个进程,进程所指包括 ...
- hashMap源码解析(五)
---恢复内容开始--- 首先抛出一个问题: 为什么hashMap一般使用String作为key? 这是我学习前辈们的博文时看到的一个问题,觉着很有意思,所以记录下来. 原因1: 我当时的第一反应是: ...