ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 insert image into large tif file straight from scanner
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndNit

Brazil
81 Posts

Posted - Jan 02 2023 :  07:56:11  Show Profile  Reply
Good Morning...

I would like to know how can I include images within the large tif file through the scanner?

I used your demo for other features and it worked fine, but I couldn't update the tiff and save straight from the scanner.



I used this example for the other functions:

https://www.imageen.com/files/demos/run/InputOutput/TiffHandler2/TiffHandler2.zip

xequte

38615 Posts

Posted - Jan 03 2023 :  19:55:49  Show Profile  Reply
Hi

You are better to use a TImageEnMView, which stores a set of images that can be saved to a multi-page TIFF file. You can add to the TImageEnMView image list by scanning or loading images from file.

Take a look at the ImageAcquisition\AllAcquire\AllAcquire.dpr demo, and let us know if you need more advice.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 04 2023 :  18:13:02  Show Profile  Reply
Hi Nigel,

I already do it the way you told me, but when I save the TImageEnMView it takes a LONG time, it's worth remembering that I'm working with 500 MB / 1GB files.

Your example for a large tif, loads an image from the directory and saves it very quickly, it's perfect, I would like to be able to do that, but capturing it from the scanner.

Using TImageEnMView, after capturing a new image directly from the scanner, I use this line to save the file, and it takes a long time, how can I resolve this issue?

One of the things I thought of was scanning to a temporary folder and then uploading the files to the tif with these codes.

Tiff.InsertPageAsFile( temporary image, insertPos );

LoadCurrentTIFFPage();

Tiff.WriteFile( SaveImageEnDialog1.FileName );

would there be anything simpler?

This is the code I use to save the TImageEnMView after adding a new image from the scanner, but, as mentioned before, it takes too long.

ImageEnMView1.MIO.SaveToFile(ImgDocPath)

Thank you for your attention.

Thanks.
Go to Top of Page

xequte

38615 Posts

Posted - Jan 04 2023 :  19:26:02  Show Profile  Reply
Hi

If you want to stick with the TIETIFFHandler you can insert images from the scanner as follows...

// Add a page from the scanner
procedure TMainForm.btnAddFromScannerClick(Sender: TObject);
var
  io: TImageEnIO;
  insertPos: integer;
begin
  io := TImageEnIO.Create( nil );
  try
    if io.Acquire() then
    begin
      insertPos := Tiff.GetPagesCount; // Append to end

      // Insert it into our TIFF
      Tiff.InsertPageAsImage( io.IEBitmap, insertPos );
  finally
    io.Free;
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 05 2023 :  08:21:00  Show Profile  Reply
Hi,

I tried to implement the code you indicated, but the tif file does not undergo any changes, neither in the file in the folder nor in the TImageEnMView component

I can scan the images normally through the scanner, but they don't go anywhere apparently lol.

Would you help me? The code I'm using is this.



procedure TfrmConsCert.bbDigitalizaClick(Sender: TObject);
var
  io: TImageEnIO;
  insertPos: integer;
begin
  io := TImageEnIO.Create( nil );
  try
    io.AcquireParams.SetSource(ieaTwain, cbSelecionaScan.Items[cbSelecionaScan.ItemIndex]);
    if io.Acquire() then
    begin
      insertPos := Tiff.GetPagesCount; // Append to end

      // Insert it into our TIFF
      Tiff.InsertPageAsImage( io.IEBitmap, insertPos );
    end;
  finally
    io.Free;
  end;
  LoadCurrentTIFFPage();
  Tiff.WriteFile(File path);
end;

Go to Top of Page

xequte

38615 Posts

Posted - Jan 05 2023 :  16:29:28  Show Profile  Reply
Sorry, the code I posted is from the current beta. In your version, please use:

procedure TfrmConsCert.bbDigitalizaClick(Sender: TObject);
var
  io: TImageEnIO;
  insertPos: integer;
begin
  io := TImageEnIO.Create( nil );
  try
    io.AcquireParams.SetSource(ieaTwain, cbSelecionaScan.Items[cbSelecionaScan.ItemIndex]);
    if io.Acquire() then
    begin
      insertPos := Tiff.GetPagesCount; // Append to end

      // Insert it into our TIFF
      Tiff.InsertPageAsImage( io, insertPos );
    end;
  finally
    io.Free;
  end;
  LoadCurrentTIFFPage();
  Tiff.WriteFile(File path);
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 05 2023 :  17:36:05  Show Profile  Reply
Primeor Thanks for the solution, but I apologize for the insistence. We are progressing well in the process, but this way, only the first page scanned is assigned to the tif file, the other pages are disregarded, how to include all pages scanned through the scanner to the tif file?
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 05 2023 :  17:46:06  Show Profile  Reply
I tried to change the variable

io: TImageEnIO;

per

mio: TImageEnMIO;

but it still doesn't work
Go to Top of Page

xequte

38615 Posts

Posted - Jan 05 2023 :  18:24:04  Show Profile  Reply
Hi

Please email me for the current beta. It allows you to add TIEBitmaps using InsertPageAsImage().

Then you can add an TImageEnMIO object to your form, and call ImageEnMIO.Acquire() to retrieve multiple scans.

In the OnAcquireBitmap bitmap event, add the scanned bitmap to the TIFF as above...

http://www.imageen.com/help/TImageEnMIO.OnAcquireBitmap.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38615 Posts

Posted - Jan 05 2023 :  18:24:46  Show Profile  Reply
If you don't wish to use the new beta, then save the acquired bitmap to a temp file and add it using InsertPageAsFile()

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 05 2023 :  18:31:59  Show Profile  Reply
Would you have an example of this last solution presented? thank you very much
Go to Top of Page

xequte

38615 Posts

Posted - Jan 05 2023 :  21:12:42  Show Profile  Reply

procedure TForm1.ImageEnMView1AcquireBitmap(Sender: TObject; ABitmap: TIEBitmap; DpiX, DpiY: Integer; var Handled: Boolean);
var
  filename: string;
begin
  filename := GetTempFolder() + 'Scan_' + FormatDateTime( 'yymmdd-hhnnss-zzz', Now ) + '.jpg';
  ABitmap.Write( filename);      
  Tiff.InsertPageAsFile( filename, Tiff.GetPagesCount );
  Handled := True;
end;

OR

procedure TForm1.ImageEnMView1AcquireBitmap(Sender: TObject; ABitmap: TIEBitmap; DpiX, DpiY: Integer; var Handled: Boolean);
begin
  Tiff.InsertPageAsImage( ABitmap, Tiff.GetPagesCount );
  Handled := True;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 12 2023 :  09:49:47  Show Profile  Reply
Hi,
I'm still having trouble scanning multiple pages and updating the Tif file. I didn't quite understand the last code you sent me and I couldn't move forward with the solution. Could you help me with this problem?
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 12 2023 :  10:03:39  Show Profile  Reply
procedure TfrmConsCert.bbDigitalizaClick(Sender: TObject);
var
  io: TImageEnIO;
  insertPos: integer;
begin
  io := TImageEnIO.Create( nil );
  try
    io.AcquireParams.SetSource(ieaTwain, cbSelecionaScan.Items[cbSelecionaScan.ItemIndex]);
    if io.Acquire() then
    begin
      insertPos := Tiff.GetPagesCount; // Append to end

      // Insert it into our TIFF
      Tiff.InsertPageAsImage( io, insertPos );
    end;
  finally
    io.Free;
  end;
  LoadCurrentTIFFPage();
  Tiff.WriteFile(File path);
end;



The way you indicated it works, but scanning one page at a time. My need is:

1: Inserting pages into an existing tif file with Multipage Scan via ADF Scanner

2 - Update the Tif file using TIETIFFHandler

3 - Save the Tif in the directory

4 - Update the thumbnails in the
TImageEnMView

I really need this solution, I count on your help.

Thanks
Go to Top of Page

xequte

38615 Posts

Posted - Jan 12 2023 :  14:13:26  Show Profile  Reply
Hi

You cannot use a TImageEnIO if you want multiple pages. You need to use a TImageEnMIO and handle each image that is returned in the ImageEnMView1AcquireBitmap event (as described above). It will be easier if you add the TImageEnMIO to your form rather than creating a temporary one.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jan 12 2023 :  15:21:08  Show Profile  Reply
Thank you very much, it worked perfectly. In case anyone needs it, the solution looks like this:


Button that calls the scanner

procedure TfrmConsCert.bbDigitalizaClick(Sender: TObject);
var
   insertPos: integer;
   ip  : integer;
   srip : TSearchRec;
begin
  try
    MIOTemp.MIO.AcquireParams.SetSource(ieaTwain, cbSelecionaScan.Items[cbSelecionaScan.ItemIndex]);
    MIOTemp.MIO.Acquire();
  finally
  end;
  LoadCurrentTIFFPage();
  Tiff.WriteFile(CaminhoImgDoc);
  LoadTiffFile(CaminhoImgDoc);
  GravaHashSHA2(CaminhoImgDoc);
  ip  := FindFirst(ExtractFilePath(Application.ExeName) + 'IncluiPagina\*.*', faAnyFile, srip);
  while ip = 0 do begin
    DeleteFile(ExtractFilePath(Application.ExeName) + 'IncluiPagina\' + srip.Name);
    ip := FindNext(srip);
  end;

event ImageEnMView1AcquireBitmap 

procedure TfrmConsCert.MIOTempAcquireBitmap(Sender: TObject; ABitmap: TIEBitmap;
  DpiX, DpiY: Integer; var Handled: Boolean);
var
  filename: string;
begin
  filename := (ExtractFilePath(Application.ExeName) + 'IncluiPagina\' +  'Scan_' + FormatDateTime( 'yymmdd-hhnnss-zzz', Now ) + '.jpg');
  ABitmap.Write( filename);
  Tiff.InsertPageAsFile( filename, Tiff.GetPagesCount );
  Handled := True;
end;
Go to Top of Page

xequte

38615 Posts

Posted - Jan 17 2023 :  19:40:43  Show Profile  Reply
Nice one

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: