WIA的ShowAcquireImage只保存在BMP中?

时间:2011-09-26 15:27:24

标签: delphi bmp wia scanning

我在Delphi XE中使用WIA 2.0库来自动扫描。我使用“ ShowAcquireImage ”功能提供要保存到光盘的图像。我想以压缩格式保存图像,例如png或jpg,但该库似乎只保存在位图中。

有没有其他人看过这个问题,还有一个workround吗? (除了将光盘保存为大型bmp文件,然后重新加载到TJpegImage / TPngImage对象中,就是这样。)

感谢您的任何建议 PhilW。

这是我目前使用的代码:

 //...
 uses   ComObj, WIA_TLB,   
 //...
procedure TMainForm.ScanWiaDocument(DocumentRef: String);
const
   wiaFormatJPEG = '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}';
   wiaFormatPNG  = '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}';
var
   CommonDlg: ICommonDialog;
   AImage: IImageFile;
   ImagePath: String;
begin
   CommonDlg := CreateOleObject('WIA.CommonDialog') as ICommonDialog;
   //Transfer as JPG
   try try
      AImage := CommonDlg.ShowAcquireImage(ScannerDeviceType,
                ColorIntent,    //or UnspecifiedIntent, GrayscaleIntent, TextIntent
                MinimizeSize,   //or MaximizeQuality
                wiaFormatJPEG,  //image format  **<----Only saves in BMP format!**!
                False,          //AlwaysSelectDevice
                False,          //UseCommonUI
                True);          //CancelError
      //Save the image
      ImagePath := 'C:\temp\scanimage\'+DocumentRef+'.'+ AImage.FileExtension;
      AImage.SaveFile(ImagePath);
   except
       on E:Exception do LogException(E, 'ScanWiaDocument', True);
   end;
   finally  //release interface
      CommonDlg := nil;
      AImage    := nil;
   end;
end;

//... uses ComObj, WIA_TLB, //... procedure TMainForm.ScanWiaDocument(DocumentRef: String); const wiaFormatJPEG = '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}'; wiaFormatPNG = '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}'; var CommonDlg: ICommonDialog; AImage: IImageFile; ImagePath: String; begin CommonDlg := CreateOleObject('WIA.CommonDialog') as ICommonDialog; //Transfer as JPG try try AImage := CommonDlg.ShowAcquireImage(ScannerDeviceType, ColorIntent, //or UnspecifiedIntent, GrayscaleIntent, TextIntent MinimizeSize, //or MaximizeQuality wiaFormatJPEG, //image format **<----Only saves in BMP format!**! False, //AlwaysSelectDevice False, //UseCommonUI True); //CancelError //Save the image ImagePath := 'C:\temp\scanimage\'+DocumentRef+'.'+ AImage.FileExtension; AImage.SaveFile(ImagePath); except on E:Exception do LogException(E, 'ScanWiaDocument', True); end; finally //release interface CommonDlg := nil; AImage := nil; end; end;

2 个答案:

答案 0 :(得分:5)

如果可能,您要求ShowAcquireImage()在JPG中捕获,但它不必遵守这一点。当ShowAcquireImage()退出时,返回的ImageFile对象具有FormatID属性,该属性指定实际使用的格式,例如,如果扫描程序不支持JPG。如果该文件尚未包含在JPG中,则必须在之后进行转换,例如使用Wia.ImageProcess对象。 MSDN显示an example of doing that

答案 1 :(得分:0)

我注意到你用于JPG和PNG的常量都是我用于BMP的常量。这可能是你的问题吗?