WIA's ShowAcquireImage only saves in BMP?
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;
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.
I noticed that the constants you used for JPG and PNG are both the one I use for BMP. Could this be your problem?
精彩评论