我使用 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/