WIA's ShowAcquireImage only saves in BMP?

感情迁移 提交于 2019-12-24 00:37:08

问题


I am using the WIA 2.0 library within Delphi XE to automate scanning. I am using the "ShowAcquireImage" function to provide an image to be saved to disc. I want to save the image in a compressed format such as png or jpg, but the library only seems to save in bitmap.

Has anyone else seen this problem, and is there a workround? (Apart from saving to disc as a big bmp file, and re-loading into a TJpegImage/TPngImage object, that is).

Thanks for any advice PhilW.

This the code I am currently using:

 //...
 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;


回答1:


You are asking ShowAcquireImage() to capture in JPG if possible, but it does not have to honor that. When ShowAcquireImage() exits, the returned ImageFile object has a FormatID property that specifies the format that was actually used, for instance if the scanner does not support JPG. If the file is not already in JPG, you will have to convert it afterwards, such as by using the Wia.ImageProcess object. MSDN shows an example of doing that.




回答2:


I noticed that the constants you used for JPG and PNG are both the one I use for BMP. Could this be your problem?



来源:https://stackoverflow.com/questions/7557430/wias-showacquireimage-only-saves-in-bmp

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