WIA的ShowAcquireImage只保存为BMP?

发布于 2024-12-06 07:44:26 字数 1506 浏览 0 评论 0原文

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

有其他人看到过这个问题吗?有解决方法吗? (除了作为大 bmp 文件保存到光盘并重新加载到 TJpegImage/TPngImage 对象中之外)。

感谢您的任何建议 菲尔W.

这是我当前使用的代码: <代码>

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

<代码>

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡风轻 2024-12-13 07:44:27

您要求 ShowAcquireImage() 如果可能的话以 JPG 格式捕获,但它不必遵守这一点。当 ShowAcquireImage() 退出时,返回的 ImageFile 对象具有一个 FormatID 属性,用于指定实际使用的格式,例如,如果扫描仪不这样做不支持JPG。如果该文件还不是 JPG 格式,则必须随后对其进行转换,例如使用 Wia.ImageProcess 对象。 MSDN 显示了执行此操作的示例

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.

若言繁花未落 2024-12-13 07:44:27

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文