c# - WIA:保存文件时不压缩

标签 c# image compression wia

我使用 WIA 扫描图像并注意到,图像存储效率不高,因为 SaveFile 显然没有使用压缩。

目前我正在使用此代码:

WIA.ImageFile img = (WIA.ImageFile)item.Transfer(WIA.FormatID.wiaFormatPNG);
img.SaveFile(path); 

有没有办法使用 WIA 进行压缩,或者我怎样才能使用压缩来保存图像?

编辑:

使用以下代码,我能够将文件大小从 25 MB 减少到 10 MB。

WIA.ImageFile img = (WIA.ImageFile)item.Transfer(WIA.FormatID.wiaFormatPNG);
WIA.ImageProcess ImageProcess1 = new WIA.ImageProcessClass();
System.Object Object1 = null;
System.Object Object2 = null;
Object1 = (Object)"Convert";
ImageProcess1.Filters.Add(ImageProcess1.FilterInfos.get_Item(ref Object1).FilterID, 0);
Object1 = (Object)"FormatID";
Object2 = (Object)WIA.FormatID.wiaFormatPNG;
ImageProcess1.Filters[1].Properties.get_Item(ref Object1).set_Value(ref Object2);
img = ImageProcess1.Apply(img);
img.SaveFile(path); 

最佳答案

获得 WIA 图像(此处显示为“图像”变量)后,您可以在保存之前应用过滤器来调整质量,如下所示:

WIA.ImageProcess myip = new WIA.ImageProcess();  // use to compress jpeg.
myip.Filters.Add(myip.FilterInfos["Convert"].FilterID);
myip.Filters[1].Properties["FormatID"].set_Value(WIA.FormatID.wiaFormatJPEG);
myip.Filters[1].Properties["Quality"].set_Value(jpgQuality);

image = myip.Apply(image);  // apply the filters
image.SaveFile(outputFilename);

在此示例中,jpgQuality 是 1 到 100 之间的 int 值。1 = 低质量,100 = 最佳质量。

关于c# - WIA:保存文件时不压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10508974/

相关文章:

c# - 在 Visual Studio 2017 中运行简单的 Hello World 时出现的错误

c# - 使用 c# 在 asp.net 中的 sqlserver 的下拉列表中显示数据

html - 图像在 CSS 过渡期间不会混合

jquery - 使用 jQuery 更改多个背景图像

c++ - 线程 : doing processing in background of C++ Cinder app to keep the UI responsive

java - GZIP压缩与解压

c# - 限制 Linq 列表中返回的结果数

Java 压缩/解压缩大文件 (>1gb)

performance - 压缩使响应时间变慢

c# - FluentFtp Azure ftp 用户在几次成功连接后无法登录