WIA的ShowAcquireImage仅保存在BMP中吗? [英] WIA's ShowAcquireImage only saves in BMP?
问题描述
我正在使用Delphi XE中的WIA 2.0库自动进行扫描.我正在使用" ShowAcquireImage "功能来提供要保存到光盘的图像.我想以压缩格式(例如png或jpg)保存图像,但是该库似乎只保存在位图中.
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.
有没有其他人看到过这个问题,并且有解决方法吗? (除了将其保存为大的bmp文件并重新加载到TJpegImage/TPngImage对象之外).
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;
推荐答案
您正在要求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.
这篇关于WIA的ShowAcquireImage仅保存在BMP中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!