ImageEn, unit iexBitmaps

TIEBitmap.RenderToCanvasWithAlpha

TIEBitmap.RenderToCanvasWithAlpha


Declaration

procedure RenderToCanvasWithAlpha(Dest: TCanvas; xDst, yDst, dxDst, dyDst: integer; xSrc, ySrc, dxSrc, dySrc: integer; Transparency: integer = 255; Filter: TResampleFilter = rfNone; RenderOperation: TIERenderOperation = ielNormal; Opacity: double = 1.0);


Description

Draws the rectangle, xSrc, ySrc, dxSrc (width), dySrc (height), within the destination rectangle, xDst, yDst, dxDst (width), dyDst (height), of Dest TCanvas object.
Transparency specifies the transparency value (0=Fully Transparent to 255=Fully Opaque).
Filter the resampling filter.
RenderOperation the rendering operation.
Opacity specifies the opacity (0=Fully Transparent to 1.0=Fully Opaque).

This function reads the destination canvas pixels and merges them with image using the alpha channel mask, i.e. painting will not occur for pixels of < 255 in the AlphaChannel


Opacity vs Transparency

Both the Opacity and Transparency parameters provide the same functionality. Transparency is the traditional ImageEn value, whereas Opacity provides easier PSD compatibility.
While they can be used in combination, generally only one will be used, i.e. leave Opacity=1 and make use of transparency, or alternatively, leave Transparency=255 and make use of Opacity. For example, for 50% opacity: Transparency = 255 and Opacity = 0.5, or Transparency = 128 and Opacity = 1.0




Examples

// Draw aIEBitmap within aRect while maintaining the aspect ratio of the image
aRect := GetImageRectWithinArea( aIEBitmap.Width, aIEBitmap.Height, aRect );
aIEBitmap.RenderToCanvasWithAlpha( aCanvas, aRect.Left, aRect.Top, aRect.Right - aRect.Left, aRect.Bottom - aRect.Top, 0, 0, aIEBitmap.Width, aIEBitmap.Height, 255, rfFastLinear );

// Draw a transparent PNG onto a canvas
var
  bmp: TBitmap;
  ieb: TIEBitmap;
  aRect: TRect;
begin
  bmp := TBitmap.Create;
  ieb := TIEBitmap.Create;
  try
    bmp.LoadFromFile( 'D:\Background.bmp' );

    ieb.Read( 'AlphaImage.png' );
    if ieb.HasAlphaChannel( True ) = False then
      raise Exception.create( 'Image has no alpha!' );

    // Calculate destination rect so PNG is centered on our background image
    aRect := GetImageRectWithinArea( ieb.Width, ieb.Height, Rect( 0, 0, bmp.Width, bmp.Height ));
    ieb.RenderToCanvasWithAlpha( bmp.Canvas,
                                 aRect.Left, aRect.Top, aRect.Right - aRect.Left, aRect.Bottom - aRect.Top,
                                 0, 0, ieb.Width, ieb.Height,
                                 255, rfFastLinear );
  finally
    bmp.Free;
    ieb.Free;
  end;
end;


See Also

 DrawToCanvasWithAlpha
 RenderToCanvas


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)