ImageEn, unit imageenview |
|
TImageEnView.CopySelectionToBitmap
Declaration
procedure CopySelectionToBitmap(DestBitmap: TBitmap; FillBackground: Boolean = True); overload;
procedure CopySelectionToBitmap(DestBitmap: TIEBitmap; FillBackground: Boolean = True); overload;
Description
Copies the current selection to the specified bitmap. The alpha channel is also copied.
If
FillBackground is enabled, then non-selected areas of the copied rectangle of the image will be filled with the
background color. Otherwise, it is transferred as alpha.
Note: To copy all or part of the image to other classes, such as TImage or TPicture, use
AssignSelTo | Demos\Other\CellsAndGrid\CellsAndGrid.dpr |
// Overload 1
ImageEnView1.CopySelectionToBitmap( MyBitmap );
// Overload 2
ImageEnView1.CopySelectionToBitmap( ImageEnView2.IEBitmap );
// If an area of the image is selected, print the selection, otherwise print the whole image
procedure TForm1.PrintImageClick(Sender: TObject);
var
bmp: TIEBitmap;
IO: TImageEnIO;
begin
if ImageEnView1.Selected = False then
ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog, '' )
else
begin
bmp := TIEBitmap.Create;
IO := TImageEnIO.CreateFromBitmap( bmp );
try
ImageEnView1.CopySelectionToBitmap( bmp );
IO.DoPrintPreviewDialog( iedtDialog, '' );
finally
IO.Free();
bmp.Free();
end;
end;
end;
// Create image layer from current selection
// Note: This is only an example. An easier method is TImageEnView.LayersCreateFromSelection
if ImageEnView1.Selected then
begin
bmp := TIEBitmap.create();
ImageEnView1.CopySelectionToBitmap( bmp, False );
ImageEnView1.LayersAdd( bmp );
ImageEnView1.CurrentLayer.PosX := ImageEnView1.SelectedRect.x;
ImageEnView1.CurrentLayer.PosY := ImageEnView1.SelectedRect.y;
ImageEnView1.Deselect;
ImageEnView1.Update();
bmp.Free();
end;
// Select a pentagonal area of the image and save it to PNG (with transparent background)
const
PENT_X1 = 0.21; PENT_Y1 = 0.41;
PENT_X2 = 0.32; PENT_Y2 = 0.74;
PENT_X3 = 0.68; PENT_Y3 = 0.74;
PENT_X4 = 0.79; PENT_Y4 = 0.41;
PENT_X5 = 0.50; PENT_Y5 = 0.20;
var
bmp: TIEBitmap;
bw, bh: Integer;
begin
ImageEnView1.SelectionBase := iesbBitmap;
bw := ImageEnView1.IEBitmap.Width;
bh := ImageEnView1.IEBitmap.Height;
ImageEnView1.BeginSelect();
ImageEnView1.AddSelPoint( Round( PENT_X1 * bw ), Round( PENT_Y1 * bh ));
ImageEnView1.AddSelPoint( Round( PENT_X2 * bw ), Round( PENT_Y2 * bh ));
ImageEnView1.AddSelPoint( Round( PENT_X3 * bw ), Round( PENT_Y3 * bh ));
ImageEnView1.AddSelPoint( Round( PENT_X4 * bw ), Round( PENT_Y4 * bh ));
ImageEnView1.AddSelPoint( Round( PENT_X5 * bw ), Round( PENT_Y5 * bh ));
ImageEnView1.EndSelect();
bmp := TIEBitmap.Create();
ImageEnView1.CopySelectionToBitmap( bmp, False );
bmp.SaveToFile( 'D:\PentagonalSelection.png' );
bmp.Free();
end;
See Also
◼ApplyBitmapToSelection