ImageEn, unit iexBitmaps

TIEBitmap.CreateROICanvas

TIEBitmap.CreateROICanvas


Declaration

function CreateROICanvas(Rect: TRect; AntiAlias: boolean = true; UseGDIPlus: boolean = true; PerformAlphaCompositing: boolean = false): TIECanvas;
function CreateROICanvas(AntiAlias: boolean = true; UseGDIPlus: boolean = true; PerformAlphaCompositing: boolean = false): TIECanvas;


Description

Creates a TIECanvas object representing a copy of specified bitmap area (i.e. a "Region of Interest" canvas).
The canvas pixel format will be temporally 24 bit RGB (or 32 bit RGB when PerformAlphaCompositing is True) and has coordinates translated to the top-left of the specified rectangle.
When the returned object is destroyed the content is copied back to the original bitmap.


Example

// create a layer on a TImageEnView with shadow text
var
  compositingCanvas: TIECanvas;
begin
  ImageEnView1.LayersAdd();

  // Area that is larger than what we need
  ImageEnView1.IEBitmap.Allocate(500, 500);
  ImageEnView1.AlphaChannel.Fill(0);

  // Rect(0,0,500,100) is just the estimated required area
  compositingCanvas := ImageEnView1.IEBitmap.CreateROICanvas(Rect(0, 0, 500, 100), true, true, true);

  compositingCanvas.Brush.Color := clRed;
  compositingCanvas.Font.Name := 'Tahoma';
  compositingCanvas.Font.Height := 72;
  compositingCanvas.DrawText('Hello World!', Rect(0, 0, 500, 300));  // use DrawText instead of TextOut

  // This will also copy the content back to the IEBitmap
  compositingCanvas.Free();

  // Add a Soft Shadow
  ImageEnView1.Proc.AddSoftShadow(5, 5, 1);

  // Remove excess transparent area
  ImageEnView1.Proc.CropTransparentBorder;

  ImageEnView1.Update();
end;


Example 2

// make area outside ellipse transparent
ImageEnView1.IO.LoadFromFile('test.jpg');
ImageEnView1.IEBitmap.AlphaChannel.Fill(0);
with ImageEnView1.IEBitmap.AlphaChannel.CreateROICanvas() do
begin
  Brush.Style := bsSolid;
  Brush.Color := RGB(255, 255, 255);
  Ellipse(0, 0, ImageEnView1.IEBitmap.Width - 1, ImageEnView1.IEBitmap.Height - 1);
  Free();
end;
ImageEnView1.Update();