как можно сканировать определенные участоки на листе

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by LeonW, 30 Oct 2014.

  1. LeonW

    LeonW New Member

    Joined:
    11 Oct 2005
    Messages:
    19
    Likes Received:
    1
    Reputations:
    0
    Здравствуйте! как можно от сканировать, через сканер определенные участки на листе а4. т.е. на а4 листе мне нужно отсканировать верх и кусочек в правом боку. спасибо!

    Code:
     
    Uses DelphiTwain;
    
    procedure TForm1.BtnReloadSourcesClick(Sender: TObject);
    begin
      if Twain.SourceManagerLoaded then
        ReloadSources;
    end;
    
    procedure TForm1.BtnScanWithDialogClick(Sender: TObject);
    begin
      Twain.SelectedSourceIndex := LBSources.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 TForm1.BtnScanWithoutDialogClick(Sender: TObject);
    begin
      Twain.SelectedSourceIndex := LBSources.ItemIndex;
    
      if Assigned(Twain.SelectedSource) then begin
        //Load source, select transference method and enable (display interface)}
        Twain.SelectedSource.Loaded := True;
        Twain.SelectedSource.ShowUI := False;
        Twain.SelectedSource.Enabled := True;
      end;
    end;
    
    procedure TForm1.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 is not installed.');
      end;
    end;
    
    procedure TForm1.DoDestroy;
    begin
      Twain.Free;//Don't forget to free Twain!
    
      inherited;
    end;
    
    procedure TForm1.ReloadSources;
    var
      I: Integer;
    begin
      LBSources.Items.Clear;
      for I := 0 to Twain.SourceCount-1 do
        LBSources.Items.Add(Twain.Source[I].ProductName);
    
      if LBSources.Items.Count > 0 then
        LBSources.ItemIndex := 0;
    end;
    
    procedure TForm1.TwainTwainAcquire(Sender: TObject; const Index: Integer;
      Image: TBitmap; var Cancel: Boolean);
    begin
      ImgHolder.Picture.Assign(Image);
      Cancel := True;//Only want one image
    end;
    
    end.
    
    
     
  2. LeonW

    LeonW New Member

    Joined:
    11 Oct 2005
    Messages:
    19
    Likes Received:
    1
    Reputations:
    0
    нашел как выделить один кусочек
    Code:
    var
     W,H,i,j: Integer;
      bmp, bmp2: TBitmap;
    begin
      bmp :=  TBitmap.Create;
      bmp2  :=  TBitmap.Create;
      bmp.loadfromfile('01b.bmp');
      W := 480;
      H := 50;
      bmp2.Width:=W;
      bmp2.Height:=H;
      BitBlt(bmp2.Canvas.Handle, 0, 0, W, H, bmp.Canvas.Handle, 100, 100, SRCCOPY);
      bmp2.SaveToFile('02b.bmp');
      image2.Picture.LoadFromFile('02b.bmp');
    
    а как сделать если нужно 2 или 3 кусочка????? т.е. одну часть в image2 другую часть в image3 image4 и.т.д
    спасибо!
     
    1 person likes this.
  3. Alexandr II

    Alexandr II -=ImperatoR=-

    Joined:
    28 Dec 2007
    Messages:
    1,069
    Likes Received:
    671
    Reputations:
    87
    а я просто листом закрывал то что мне не нужно сканировать...
     
    1 person likes this.
  4. SpRyt

    SpRyt Member

    Joined:
    18 Oct 2010
    Messages:
    45
    Likes Received:
    5
    Reputations:
    5
    А что мешает вызвать эту функцию [BitBlt(bmp2.Canvas.Handle, 0, 0, W, H, bmp.Canvas.Handle, 100, 100, SRCCOPY)] "n" раз и сохранять выразанные кусочки? Если видишь зависимость высоты-ширины-координат - обрабатываешь в цикле.
     
  5. altblitz

    altblitz Elder - Старейшина

    Joined:
    5 Jun 2009
    Messages:
    3,694
    Likes Received:
    3,149
    Reputations:
    236
    ТС, ознакомь себя с Irfanview - конкретно, как в коммандой строке делать сжатие изображений и сохранять их.