Author |
Topic |
|
PStadler
Austria
60 Posts |
Posted - Mar 31 2014 : 04:39:53
|
Hello,
This question may have asked many times, but I did not find it.
How can two or more scans be put together to one image in imageen. Is there a demo?
Any help appreciated!
Sincerely Peter |
|
xequte
38608 Posts |
Posted - Apr 01 2014 : 00:18:52
|
Hi Peter
Do you mean that from images A and B you would create one big image with A on the left and B on the right, for example?
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
PStadler
Austria
60 Posts |
Posted - Apr 01 2014 : 01:44:29
|
Nigel,
Yes!
Sincerely Peter |
|
|
xequte
38608 Posts |
Posted - Apr 01 2014 : 13:32:41
|
Hi Peter
Well, there are the standard TCanvas routines, of course, but you can use the methods in TIEBitmap.
// Load input files
IEBitmap1.Read('D:\MyPic1.png');
IEBitmap2.Read('D:\MyPic2.jpg');
// Get Left position for IEBitmap2
iBitmap1Width := IEBitmap1.Width;
// Resize IEBitmap1
IEBitmap1.Resize(IEBitmap1.Width + IEBitmap2.Width, iMax(IEBitmap1.Height, IEBitmap2.Height), clWhite, 255, iehLeft, ievCenter);
// Draw IEBitmap2
IEBitmap2.RenderToTIEBitmapEx(IEBitmap1, iBitmap1Width, 0, IEBitmap2.Width, IEBitmap2.Height, 0, 0, IEBitmap2.Width, IEBitmap2.Height, 255, rfLanczos3, ielNormal, 1.0);
// Save output file
IEBitmap2.Write('D:\Output.png');
(Naturally you will need to create and free the IEBitmaps and will want to improve the code to adequately center both images).
Note that in the next release the complex RenderToTIEBitmapEx can be replaced by DrawToTIEBitmap:
// Load input files
IEBitmap1.Read('D:\MyPic1.png');
IEBitmap2.Read('D:\MyPic2.jpg');
// Get Left position for IEBitmap2
iBitmap1Width := IEBitmap1.Width;
// Resize IEBitmap1
IEBitmap1.Resize(IEBitmap1.Width + IEBitmap2.Width, iMax(IEBitmap1.Height, IEBitmap2.Height), clWhite, 255, iehLeft, ievCenter);
// Draw IEBitmap2
IEBitmap2.DrawToTIEBitmap(IEBitmap1, iBitmap1Width, 0);
// Save output file
IEBitmap2.Write('D:\Output.png');
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
w2m
USA
1990 Posts |
Posted - Apr 01 2014 : 16:15:58
|
Just for fun I took Nigel's code and made a small demo. It does not use the scanner but it shows how it works with tested code in a small app. CODE
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.ExtDlgs,
imageenview, ieview, imageenio, imageenproc, hyieutils, hyiedefs,
iexhelperfunctions;
type
TForm1 = class(TForm)
Panel1: TPanel;
StatusBar1: TStatusBar;
ImageEnView1: TImageEnView;
Combine1: TButton;
Open1: TButton;
Open2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
procedure Combine1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Open1Click(Sender: TObject);
procedure Open2Click(Sender: TObject);
private
{ Private declarations }
AIEImageList: TIEImageList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Combine1Click(Sender: TObject);
{ Combine two pictures into 1 }
var
iIEBitmap1: TIEBitmap;
iIEBitmap2: TIEBitmap;
iBitmap1Width: integer;
begin
{ Create a TIEBitmap to hold image 1 }
iIEBitmap1 := TIEBitmap.Create;
try
{ Create a TIEBitmap to hold image 2 }
iIEBitmap2 := TIEBitmap.Create;
try
{ Load input files }
iIEBitmap1.Assign(AIEImageList.Image[0]);
iIEBitmap2.Assign(AIEImageList.Image[1]);
{ Prevent getting a huge bitmap with large images by resampling both bitmaps }
iIEBitmap1.Resample(1024, 768);
iIEBitmap2.Resample(1024, 768);
{ Get Left position for IEBitmap2 }
iBitmap1Width := iIEBitmap1.Width;
{ Resize IEBitmap1 }
iIEBitmap1.Resize(iIEBitmap1.Width + iIEBitmap2.Width,
iMax(iIEBitmap1.Height, iIEBitmap2.Height), clWhite, 255, iehLeft,
ievCenter);
{ Draw IEBitmap2 }
iIEBitmap2.RenderToTIEBitmapEx(iIEBitmap1, iBitmap1Width, 0,
iIEBitmap2.Width, iIEBitmap2.Height, 0, 0, iIEBitmap2.Width,
iIEBitmap2.Height, 255, rfLanczos3, ielNormal, 1.0);
{ Optional - Save output file }
{ iIEBitmap1.Write('D:\Output.png'); }
ImageEnView1.IEBitmap.Assign(iIEBitmap1);
ImageEnView1.Update;
ImageEnView1.FitToHeight;
finally
{ Free TIEBitmap1 }
iIEBitmap1.Free;
end;
finally
{ Free TIEBitmap2 }
iIEBitmap2.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
{ Form Create. }
begin
{ Enable gestures }
ImageEnView1.Gestures.Pan.Enabled := True;
ImageEnView1.Gestures.Zoom.Enabled := True;
{ Create a TIEImageList to hold the pictures }
AIEImageList := TIEImageList.Create;
{ Register ImageEnIO file formats with TPicture }
IERegisterFormats;
{ Set the OpenPictureDialog Filter }
OpenPictureDialog1.Filter := GraphicFilter(TGraphic);
end;
procedure TForm1.FormDestroy(Sender: TObject);
{ Free the AIEImageList and UnRegister Formats }
begin
AIEImageList.Free;
IEUnRegisterFormats;
end;
procedure TForm1.Open1Click(Sender: TObject);
{ Open Picture 1 }
var
iFileName: string;
iIEBitmap: TIEBitmap;
begin
AIEImageList.Clear;
if OpenPictureDialog1.Execute then
begin
{ Create a TIEBitmap to hold image 1 }
iIEBitmap := TIEBitmap.Create;
try
iFileName := OpenPictureDialog1.Filename;
{ Open the file }
iIEBitmap.IELoadFromFile(iFileName);
{ Save the image to the list }
AIEImageList.AppendImageRef(TIEBitmap.Create(iIEBitmap), iFileName);
finally
{ Free the IIEBitmap }
iIEBitmap.Free;
end;
end;
end;
procedure TForm1.Open2Click(Sender: TObject);
{ Open Picture 2 }
var
iFileName: string;
iIEBitmap: TIEBitmap;
begin
if OpenPictureDialog1.Execute then
begin
{ Create a TIEBitmap to hold image 1 }
iIEBitmap := TIEBitmap.Create;
try
iFileName := OpenPictureDialog1.Filename;
// Open the file
iIEBitmap.IELoadFromFile(iFileName);
// Save the image to the list
AIEImageList.AppendImageRef(TIEBitmap.Create(iIEBitmap), iFileName);
finally
{ Free the IIEBitmap }
iIEBitmap.Free;
end;
end;
end;
end.
DFM
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Combine Two Pictures Into One'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 635
Height = 41
Align = alTop
BevelOuter = bvNone
TabOrder = 0
object Combine1: TButton
Left = 171
Top = 9
Width = 75
Height = 25
Caption = 'Combine'
TabOrder = 0
OnClick = Combine1Click
end
object Open1: TButton
Left = 9
Top = 9
Width = 75
Height = 25
Caption = 'Open 1'
TabOrder = 1
OnClick = Open1Click
end
object Open2: TButton
Left = 90
Top = 9
Width = 75
Height = 25
Caption = 'Open 2'
TabOrder = 2
OnClick = Open2Click
end
end
object StatusBar1: TStatusBar
Left = 0
Top = 280
Width = 635
Height = 19
Panels = <>
end
object ImageEnView1: TImageEnView
Left = 0
Top = 41
Width = 635
Height = 239
Background = clBtnFace
ParentCtl3D = False
EnableInteractionHints = True
Align = alClient
TabOrder = 2
end
object OpenPictureDialog1: TOpenPictureDialog
Left = 35
Top = 63
end
end Something similar to this could also be written that places picture 1 in Layer 1 and places picture 2 into layer 2. Then the layer positions and dimensions are adjusted accordingly to fit the base bitmap in layer 0... but Nigel's approach is the simplest way. An unlimited number of pictures can be placed side-by-side which can be scrolled or panned with touch gestures like that shown in my Android Like Touch Enabled Image Viewer Demo shown on this page http://www.imageen.com/ieforum/topic.asp?TOPIC_ID=1446
William Miller Adirondack Software & Graphics Email: w2m@frontiernet.net EBook: http://www.imageen.com/ebook/ Apprehend: http://www.frontiernet.net/~w2m/index.html Custom ImageEn Development |
|
|
PStadler
Austria
60 Posts |
Posted - Apr 01 2014 : 21:58:46
|
Hello Nigel and Bill,
Thanks a lot. I will give it a try!
Sincerely
Peter |
|
|
xequte
38608 Posts |
Posted - Apr 02 2014 : 00:03:30
|
@Bill
Nice demo
Perhaps the following would be better so the aspect ratio is maintained:
...
{ Prevent getting a huge bitmap with large images by resampling both bitmaps }
iIEBitmap1.Resample(-1, 768);
iIEBitmap2.Resample(-1, 768);
...
Nigel Xequte Software www.xequte.com nigel@xequte.com
|
|
|
|
Topic |
|
|
|