WIA的ShowAcquireImage只保存为BMP?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您要求 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. WhenShowAcquireImage()
exits, the returnedImageFile
object has aFormatID
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 theWia.ImageProcess
object. MSDN shows an example of doing that.我注意到您用于 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?