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
 Duplex scan front + back and combine TImageEnView
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Craigism

USA
2 Posts

Posted - Jul 25 2017 :  22:40:13  Show Profile  Reply
Duplex scan front + back and combine to a single TImageEnView
I want to save to a single JPG. I'm not trying to do multi-page frames.

I basically have an insurance card and a duplex scanner. If I use a "card scanner", its twain driver makes one image out both sides automatically. My issue is, if I use a full page duplex scanner then I would like to know how to best get page one and two to combine into one image.

I looked at the many examples and I do not see a clear example.

Thank you in advance.

~Craig

xequte

38186 Posts

Posted - Jul 27 2017 :  20:40:19  Show Profile  Reply
Hi Craig

You can use the following helper methods to join two images:
(They will be included in iexHelperFunctions in the next update).

procedure IEJoinBitmaps(Dest: TIEBitmap; Src1, Src2: TIEBitmap; Vertical: Boolean; BGColor: TColor = clBlack);
var
  imgLeft, imgTop: Integer;
  totalWidth, totalHeight: Integer;
begin
  if Vertical then
  begin
    totalWidth  := max( Src1.Width, Src2.Width );
    totalHeight := Src1.Height + Src2.Height;
  end
  else
  begin
    totalWidth  := Src1.Width + Src2.Width;
    totalHeight := max( Src1.Height, Src2.Height );
  end;

  Dest.IEInitialize( totalWidth, totalHeight, BGColor );

  if Vertical then
  begin
    imgLeft := ( totalWidth - Src1.Width ) div 2;
    imgTop  := 0;
    Src1.DrawToTIEBitmap( Dest, imgLeft, imgTop );

    imgLeft := ( totalWidth - Src2.Width ) div 2;
    imgTop  := Src1.Height;
    Src2.DrawToTIEBitmap( Dest, imgLeft, imgTop );
  end
  else
  begin
    imgLeft := 0;
    imgTop  := ( totalHeight - Src1.Height ) div 2;
    Src1.DrawToTIEBitmap( Dest, imgLeft, imgTop );

    imgLeft := Src1.Width;
    imgTop  := ( totalHeight - Src2.Height ) div 2;
    Src2.DrawToTIEBitmap( Dest, imgLeft, imgTop );
  end;
end;

procedure IEJoinBitmaps(Dest: TBitmap; Src1, Src2: TBitmap; Vertical: Boolean; BGColor: TColor = clBlack);
var
  imgLeft, imgTop: Integer;
  totalWidth, totalHeight: Integer;
begin
  if Vertical then
  begin
    totalWidth  := max( Src1.Width, Src2.Width );
    totalHeight := Src1.Height + Src2.Height;
  end
  else
  begin
    totalWidth  := Src1.Width + Src2.Width;
    totalHeight := max( Src1.Height, Src2.Height );
  end;

  Dest.IEInitialize( totalWidth, totalHeight, BGColor );

  if Vertical then
  begin
    imgLeft := ( totalWidth - Src1.Width ) div 2;
    imgTop  := 0;
    Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src1.Width, imgTop + Src1.Height ),
                          Src1.Canvas,
                          Rect( 0, 0, Src1.Width, Src1.Height ));

    imgLeft := ( totalWidth - Src2.Width ) div 2;
    imgTop  := Src1.Height;
    Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src2.Width, imgTop + Src2.Height ),
                          Src2.Canvas,
                          Rect( 0, 0, Src2.Width, Src2.Height ));
  end
  else
  begin
    imgLeft := 0;
    imgTop  := ( totalHeight - Src1.Height ) div 2;
    Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src1.Width, imgTop + Src1.Height ),
                          Src1.Canvas,
                          Rect( 0, 0, Src1.Width, Src1.Height ));

    imgLeft := Src1.Width;
    imgTop  := ( totalHeight - Src2.Height ) div 2;
    Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src2.Width, imgTop + Src2.Height ),
                          Src2.Canvas,
                          Rect( 0, 0, Src2.Width, Src2.Height ));
  end;
end;


Here's some example usage:

procedure TMain.Button1Click(Sender: TObject);
begin
  ImageEnView1.LegacyBitmap := False;
  ImageEnView2.LegacyBitmap := False;
  ImageEnView3.LegacyBitmap := False;

  ImageEnView1.IO.LoadFromFile( 'D:\_Testfiles\Image1.jpg' );
  ImageEnView2.IO.LoadFromFile( 'D:\_Testfiles\Image2.bmp' );

  IEJoinBitmaps( ImageEnView3.IEBitmap, ImageEnView1.IEBitmap, ImageEnView2.IEBitmap, False );
  ImageEnView3.Update();
end;



Or see this demo:

attach/xequte/201772720408_JoinBitmaps.zip
49.47 KB

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