ImageEn, unit iexBitmaps

TIEBitmap.StretchRectTo

TIEBitmap.StretchRectTo


Declaration

procedure StretchRectTo(Dest: TIEBitmap; xDst, yDst, dxDst, dyDst: integer; xSrc, ySrc, dxSrc, dySrc: integer; Filter: TResampleFilter; Transparency: integer = 255; Opacity: double = 1.0);


Description

Stretches source rectangle in destination rectangle.
This method doesn't merge the image with the background, but just replace it (image and alpha).
This function assumes that there is an alpha channel (if not creates it).
The PixelFormat of Dest must be ie24RGB. The source image can be ie24RGB or ie1g.


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 the full image of iebmp to the rect (100, 100, 300, 300)
iebmp.StretchRectTo( ImageEnView1.IEBitmap, 100, 100, 200, 200, 0, 0, iebmp.Width, iebmp.Height, rfLanczos3 );
ImageEnView1.Update();


// Draw two images onto a bitmap above
// Image 1 is centered within the top 30% of the bitmap. Image 2 is centered within the bottom 70% of the bitmap
const
  // Size to draw image 1
  Image_1_Max_Width  = 900;
  Image_1_Max_Height = 300;                 // 30% of output image height

  // Size to draw image 2
  Image_2_Max_Width  = Image_1_Max_Width;
  Image_2_Max_Height = 700;                 // 70% of output image height

  // Size of output image
  Image_Out_Width    = Image_1_Max_Width;
  Image_Out_Height   = Image_1_Max_Height + Image_2_Max_Height;

  BG_Color           = clWhite;
var
  bmpOut, bmp1, bmp2 : TIEBitmap;
  rct1, rct2: TRect;
begin
  bmp1 := TIEBitmap.Create();
  bmp2 := TIEBitmap.Create();
  bmpOut := TIEBitmap.Create( Image_Out_Width, Image_Out_Height, BG_Color );
  try
    bmp1.LoadFromFile( 'D:\Image1.jpg' );
    bmp2.LoadFromFile( 'D:\Image2.jpg' );

    // Draw bmp1 at top of image within allowed space (while maintaing AR)
    rct1 := GetImageRectWithinArea( bmp1.Width, bmp1.Height,
                                    Image_1_Max_Width, Image_1_Max_Height );
    bmp1.StretchRectTo( bmpOut,
                        rct1.Left, rct1.Top,  rct1.Right - rct1.Left, rct1.Bottom - rct1.Top,
                        0, 0, bmp1.Width, bmp1.Height,
                        rfLanczos3 );

    // Draw bmp2 below bmp1 within allowed space (while maintaing AR)
    rct2 := GetImageRectWithinArea( bmp2.Width, bmp2.Height,
                                    Image_2_Max_Width, Image_2_Max_Height );
    bmp2.StretchRectTo( bmpOut,
                        rct2.Left, Image_1_Max_Height + rct2.Top,  rct2.Right - rct2.Left, rct2.Bottom - rct2.Top,
                        0, 0, bmp2.Width, bmp2.Height,
                        rfLanczos3 );

    // Show in our TImageEnView
    ImageEnView1.Assign( bmpOut );

  finally
    bmp1 .Free;
    bmp2 .Free;
    bmpOut.Free;
  end;
end;


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 bitmap
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)