WIA: no compression when saving files

余生颓废 提交于 2020-01-03 02:58:29

问题


I'm using WIA for scanning images and noticed, that images aren't stored efficiently as SaveFile apparently doesn't make use of compression.

Currently I'm using this code:

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

Is there a way to use WIA for compression, or how else could I save the image using compression?

EDIT:

Using the following code I was able to decrease file size from 25 to 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); 

回答1:


Basically you should add a compression filter before you save your image, in this url you can find a sample of tiff/jpg compression:

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




回答2:


After you have gotten your WIA Image (shown here as the 'image' variable), you apply a filter to adjust quality, before saving, like so:

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);

In this example, jpgQuality is an int value between 1 and 100. 1 = low quality, 100 = best.



来源:https://stackoverflow.com/questions/10508974/wia-no-compression-when-saving-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!