1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| { ======================================================================= }
procedure TF_Princ.Button1Click(Sender: TObject);
const
wiaCommandTakePicture = '{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}'; // <a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-consts-commandid" target="_blank">https://docs.microsoft.com/en-us/pre...nsts-commandid</a>
wiaFormatBMP = '{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}'; // <a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-consts-formatid" target="_blank">https://docs.microsoft.com/en-us/pre...onsts-formatid</a>
function GetSelectedDevice(ADeviceManager: IDeviceManager): IDevice;
var
I, K : Integer;
S : string;
S1 : string;
begin
for I := 1 to ADeviceManager.DeviceInfos.Count do
begin
Memo1.Lines.Add(' ............................. ') ;
if ADeviceManager.DeviceInfos.Item[I].type_ = ScannerDeviceType then
begin
S := '';
for K := 1 to ADeviceManager.DeviceInfos.Item[I].Properties.Count do
begin
if ADeviceManager.DeviceInfos.Item[I].Properties.Item[K].type_ = StringPropertyType then
Begin
S1 := ADeviceManager.DeviceInfos.Item[I].Properties.Item[K].Name + ':' +
ADeviceManager.DeviceInfos.Item[I].Properties.Item[K].Get_Value + ' ';
S := S + Chr(13)+ S1;
Memo1.Lines.Add(S1)
End ;
end;
if MessageDlg(S, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
Begin
Result := ADeviceManager.DeviceInfos.Item[I].Connect();
Exit ;
End ;
end;
end;
Abort;
end;
function GetSelectedCommand(ADevice: IDevice): string;
var
I : Integer;
S : string;
S1 : string;
begin
for I := 1 to ADevice.Commands.Count do
begin
S := ADevice.Commands.Item[I].Name + ':' + ADevice.Commands.Item[I].Description ;
Memo1.Lines.Add(S) ;
if MessageDlg(S, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
Result := ADevice.Commands.Item[I].CommandID; // wiaCommandTakePicture ??? wiaCommandChangeDocument ????
Exit;
end;
end;
Abort;
end;
var
DeviceManager: IDeviceManager;
DeviceScanner: IDevice;
CommandResult: IItem;
OleImage: OleVariant;
AImage: IImageFile;
Fichier : String ;
begin
Memo1.Clear ;
DeviceManager := CreateOleObject('WIA.DeviceManager') as IDeviceManager;
DeviceScanner := GetSelectedDevice(DeviceManager);
Memo1.Lines.Add(' ---------------------------------- ') ;
if DeviceScanner.type_ = ScannerDeviceType then
begin
ShowMessage('1') ;
// CommandResult := DeviceScanner.ExecuteCommand(wiaCommandTakePicture);
CommandResult := DeviceScanner.ExecuteCommand(GetSelectedCommand(DeviceScanner));
Memo1.Lines.Add(' ================================= ') ;
ShowMessage('2') ;
OleImage := CommandResult.Transfer(wiaFormatBMP);
ShowMessage('3') ;
// if VarIsType(OleImage, varDispatch) and Supports(OleImage, IImageFile, AImage) then
if VarIsType(OleImage, VarUnknown) and Supports(OleImage, IImageFile, AImage) then
Begin
ShowMessage('4') ;
Fichier := ExtractFilePath(Application.ExeName) + FormatDateTime('YYYYMMDD_HHNNSSZZZ.', Now()) + AImage.FileExtension;
If FileExists(Fichier) Then DeleteFile(Fichier) ;
AImage.SaveFile(Fichier);
Image1.Picture.Bitmap.LoadFromFile(Fichier) ;
End
Else
ShowMessage('0') ;
end;
end; |
Partager