WIA: no compression when saving files

2019-06-07 06:02发布

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

2条回答
Anthone
2楼-- · 2019-06-07 06:42

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.

查看更多
狗以群分
3楼-- · 2019-06-07 06:45

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

查看更多
登录 后发表回答