ImageEn, unit iexBitmaps

TIEBitmap.RenderToCanvas

TIEBitmap.RenderToCanvas


Declaration

procedure RenderToCanvas(DestCanvas: TCanvas; xDst, yDst, dxDst, dyDst: integer; Filter: TResampleFilter; Gamma: double = 0; BackgroundColor: TColor = clWhite; MaintainAR: Boolean = False); overload;
procedure RenderToCanvas(DestCanvas: TCanvas; DestRect: TRect; Filter: TResampleFilter; Gamma: double = 0; BackgroundColor: TColor = clWhite; MaintainAR: Boolean = False); overload;


Description

Draws the bitmap to the DestCanvas at the rectangle specified by xDst, yDst, dxDst, dyDst.
Filter specifies the filter if the image needs to be resampled.
Gamma is the gamma correction.
BackgroundColor specifies the background color when pixels aren't opaque.
MaintainAR adjusts the passed destination values to ensure the image is not skewed (maintains its original aspect ratio).

Note: If RenderToCanvas is used with an image with an alpha channel, the image will be modified. Use RenderToCanvasWithAlpha if the source bitmap has an alpha channel that should be respected when drawing.


Example

// Col 1 of a TStringGrid displays a thumbnail drawn from a TImageEnMView
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Longint;
  Rect: TRect; State: TGridDrawState);
var
  aIEBitmap: IEBitmap;
  aCanvas: TCanvas;
  idx: Integer;
begin
  // Col 1 contains thumbnail. Row 0 is fixed header row
  if (ACol <> 1) or (ARow = 0) then
    Exit;

  idx := ARow;
  aCanvas := (Sender as TStringGrid).Canvas;

  // Clear current cell rect
  aCanvas.FillRect( Rect );

  // Get our image
  // Note: don't need to create or free the TIEBitmap
  aIEBitmap := ImageEnMView1.GetIEBitmap( idx );

  // Adjust our rect to maintain the image aspect ratio
  Rect := GetImageRectWithinArea( Rect, aIEBitmap.Width, aIEBitmap.Height );

  // Draw the image
  aIEBitmap := RenderToCanvas( aCanvas, Rect.Left, Rect.Top, Rect.Right - Rect.Left,   Rect.Bottom - Rect.Top, rfFastLinear, 0 );

  // Release our image
  ImageEnMView1.ReleaseBitmap( idx, False );
end;


See Also

 DrawToCanvas
 RenderToCanvasWithAlpha


TIEBitmap Assignment and Drawing Methods

TIEBitmap Methods
Method Mode Purpose
Assign From TIEBitmap/TBitmap/TGraphic/TIcon Copy whole image
AssignImage From TIEBitmap Like assign, but does not copy the alpha channel
AssignRect From TIEBitmap/TBitmap Copy a specified rect
CopyAndConvertFormat From TIEBitmap Copy whole image
CopyRectTo To TIEBitmap Copy rect to another image (without scaling)
CopyWithMask1 To TIEBitmap Copy image using a mask to specify what is copied from the source
CopyWithMask2 To TIEBitmap Copy image using a mask to specify what is replaced in the destintation
DrawToTIEBitmap To TIEBitmap Copies all or part of the image to a specified position and/or size
JoinBitmaps From two TIEBitmaps Draws two bitmaps to a single bitmaps
MergeAlphaRectTo With TIEBitmap Merges the alpha channels of two TIEBitmaps using merge rules
MergeWithAlpha With TIEBitmap Merges all or part of two TIEBitmaps with alpha channels to a specified position
RenderToTIEBitmapEx To TIEBitmap Extended drawing of content to a TIEBitmap
StretchRectTo To TIEBitmap Copy rect to dest rect in another image (with scaling)
SwitchTo To TIEBitmap Move content from one TIEBitmap to another

TBitmap Methods
Method Mode Purpose
Assign From TIEBitmap/TBitmap/TGraphic/TIcon Copy whole image
AssignTo To TIEBitmap/TBitmap Copy whole image with optional scaling
AssignRect From TIEBitmap/TBitmap Copy a specified rect
CopyFromTBitmap From TBitmap Copy whole image
CopyToTBitmap To TBitmap Copy whole image
RenderToTBitmapEx To TBitmap Extended drawing of content to a TBitmap

TCanvas Methods
Method Mode Purpose
DrawToCanvas To TCanvas Copies whole image to canvas at specified position (ignoring the alpha channel)
DrawToCanvasWithAlpha To TCanvas Copies whole image to canvas at specified position (honoring the alpha channel)
RenderToCanvas To TCanvas Extended drawing of content to a TCanvas (ignoring the alpha channel)
RenderToCanvasWithAlpha To TCanvas Extended drawing of content to a TCanvas (honoring the alpha channel)