Einzelnen Beitrag anzeigen

HPB

Registriert seit: 2. Jun 2008
365 Beiträge
 
Delphi XE7 Professional
 
#5

AW: Über WIA scannen will nicht

  Alt 26. Mär 2015, 17:46
Hallo Lemmy,
vielen Dank für Deine Antwort.
Hier nun der komplette Code:
Delphi-Quellcode:
unit formDokumenteScannen;

interface
uses
  Winapi.Windows,
  WinApi.Messages,
  System.SysUtils,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.Menus,
  Vcl.ExtCtrls,
  Vcl.ActnList,
  Vcl.ImgList,
  Vcl.StdCtrls,

  AdvToolBar,
  AdvToolBarStylers,
  AdvPreviewMenu,
  AdvPreviewMenuStylers,
  AdvShapeButton,
  AdvOfficeStatusBar,
  AdvOfficeStatusBarStylers,
  AdvGlowButton,
  FormSize,
  AdvMenus,
  AdvOfficePager,
  AdvOfficePagerStylers,
  AdvPanel,

  DelphiTwain,
  DelphiTwain_VCL;

type
  TfrmDokumenteScannen = class(TAdvToolBarForm)
    AdvToolBarPager1: TAdvToolBarPager;
    AdvPage1: TAdvPage;
    AdvToolBarOfficeStyler1: TAdvToolBarOfficeStyler;
    AdvToolBar1: TAdvToolBar;
    AdvShapeButton1: TAdvShapeButton;
    AdvPreviewMenu1: TAdvPreviewMenu;
    AdvPreviewMenuOfficeStyler1: TAdvPreviewMenuOfficeStyler;
    AdvOfficeStatusBar1: TAdvOfficeStatusBar;
    AdvOfficeStatusBarOfficeStyler1: TAdvOfficeStatusBarOfficeStyler;
    AdvQuickAccessToolBar1: TAdvQuickAccessToolBar;
    ImageListOffice: TImageList;
    FormSize1: TFormSize;
    AdvMenuStyler1: TAdvMenuStyler;
    ActionListBPS: TActionList;
    ActionbpsHome: TAction;
    ActionMailAnBPS: TAction;
    ActionPrgTeil: TAction;
    ActionProgramminformation: TAction;
    ActionWhatsNewBPS: TAction;
    ImageListBPS: TImageList;
    advfcpgrfcstylr1: TAdvOfficePagerOfficeStyler;
    advpnlLeft: TAdvPanel;
    advpnlstylr1: TAdvPanelStyler;
    lstScanner: TListBox;
    advpnl1: TAdvPanel;
    imgHolder: TImage;
    advglwbtnScannen: TAdvGlowButton;
    advglwbtnScannerEinlesen: TAdvGlowButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure advglwbtnScannerEinlesenClick(Sender: TObject);
    procedure advglwbtnScannenClick(Sender: TObject);
  private
    { Private declarations }
    Twain: TDelphiTwain;

    procedure ReloadSources;
    procedure TwainTwainAcquire(Sender: TObject; const Index: Integer;
      Image: TBitmap; var Cancel: Boolean);
  protected
    { Protected declarations }
  public
    { Public declarations }
    procedure DoCreate; override;
    procedure DoDestroy; override;
  end;

var
  frmDokumenteScannen: TfrmDokumenteScannen;

implementation

{$R *.dfm}

procedure TfrmDokumenteScannen.advglwbtnScannenClick(Sender: TObject);
begin
  Twain.SelectedSourceIndex := lstScanner.ItemIndex;

  if Assigned(Twain.SelectedSource) then
  begin
    //Load source, select transference method and enable (display interface)}
    Twain.SelectedSource.Loaded := True;
    Twain.SelectedSource.ShowUI := True; //display interface
    Twain.SelectedSource.Enabled := True;
  end;
end;

procedure TfrmDokumenteScannen.advglwbtnScannerEinlesenClick(Sender: TObject);
begin
  ReloadSources;
end;

procedure TfrmDokumenteScannen.DoCreate;
begin
  inherited;

  Twain := TDelphiTwain.Create;
  Twain.OnTwainAcquire := TwainTwainAcquire;

  if Twain.LoadLibrary then
  begin
    //Load source manager
    Twain.SourceManagerLoaded := TRUE;

    ReloadSources;
  end
  else
  begin
    ShowMessage('Twain ist nicht installiert.');
  end;
end;

procedure TfrmDokumenteScannen.DoDestroy;
begin
  inherited;
  Twain.Free; //Don't forget to free Twain!
end;


procedure TfrmDokumenteScannen.FormClose(Sender: TObject; var Action:
  TCloseAction);
begin
  action := caFree;
end;

procedure TfrmDokumenteScannen.ReloadSources;
var
  i: Integer;
begin
  lstScanner.Items.Clear;
  for i := 0 to Twain.SourceCount - 1 do
    lstScanner.Items.Add(Twain.Source[i].ProductName);

  if lstScanner.Items.Count > 0 then
    lstScanner.ItemIndex := 0;
end;

procedure TfrmDokumenteScannen.TwainTwainAcquire(Sender: TObject;
  const Index: Integer; Image: TBitmap; var Cancel: Boolean);
begin
  imgHolder.Picture.Assign(Image);
  Cancel := True; //Only want one image
end;
Der Code ist identisch mit dem Demo-Code.
Mit Gruß
HPB
  Mit Zitat antworten Zitat