2012-05-09 68 views
1

我使用WIA扫描图像并注意到,图像未被有效存储,因为SaveFile显然没有使用压缩。WIA:保存文件时无压缩

目前我使用此代码:

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

是否有使用WIA进行压缩的方式,不然怎么我还能节省使用压缩的形象呢?

编辑:

使用下面的代码,我能够从25到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); 

回答

0

基本上你应该添加一个压缩过滤您保存图片前,在这个网址,你可以找到TIFF/JPG压缩的样本:

http://www.debugging.com/bug/18157

+1

你可以发布一些示例代码?链接有一个不幸的趋势打破。 –

0

你已经得到了你的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是一个n int值在1和100之间。1 =低质量,100 =最好。

相关问题