ImageEn, unit ieGdiPlus

TIECanvas.GradientFillRect

TIECanvas.GradientFillRect

Declaration

procedure GradientFillRect(aRect: TRect; Dir: TIEGDIPlusGradient = gpgVertical);
procedure GradientFillRect(aRect: TRect; FromColor, ToColor: TColor; Dir: TIEGDIPlusGradient = gpgVertical);

Description

Fill an area with a gradient.

With first overload:
◼From Color is specified by Brush.Color and Brush.Transparency
◼To Color is specified by Brush.BackColor and Brush.BackTransparency

aRect is treated like a VCL rect, i.e. Right and Bottom are exclusive, so Rect( 0, 0, Width, Height ) fills the whole bitmap.
Note: This differs from FillRect, which under GDI+ paints (Right-Left-1)x(Bottom-Top-1).

Examples

Also see: Automated Samples
// Fill image with a vertical gradient from yellow to red
ImageEnView1.IEBitmap.IECanvas.GradientFillRect( Rect( 0, 0, ImageEnView1.IEBitmap.Width, ImageEnView1.IEBitmap.Height ), clYellow, clRed, gpgVertical );
ImageEnView1.Update();


// Create an alpha gradient image
var
  ieBmp: TIEBitmap;
  r: TRect;
begin
  ieBmp := TIEBitmap.Create(320, 240, clWhite );
  try
    r := ieBmp.IECanvas.GDICanvas.ClipRect;
    InflateRect( r, 1, 1 );      // Because Fill may smooth edges

    // Fill image with purple
    ieBmp.IECanvas.FillRect( r, clPurple );

    // Draw gradient to our alpha channnel
    ieBmp.AlphaChannel.PixelFormat := ie24RGB;   // Temporary promote the alpha channel to 24bit to get smoother gradient
    ieBmp.AlphaChannel.IECanvas.GradientFillRect( r, clWhite, clBlack, gpgDiagonal );
    ieBmp.SyncAlphaChannel();                              // Now revert alpha to ie8g

    ieBmp.SaveToFile( 'D:\AlphaGradient.png' );
  finally
    ieBmp.Free();
  end;
end;

See Also

◼IEDrawGradientToComboListBoxItem

Compatibility Information

Prior to v15.2.4, GradientFillRect did not paint the last column and row of aRect (as for FillRect). From v15.1.0, this appeared as a line of the original background along the right and bottom edges. GradientFillRect now fills the full rect (Right and Bottom exclusive).
If your code enlarged the rect to compensate, it will now fill one extra pixel to the right and bottom. This only matters if you are not filling the whole bitmap (filling beyond the bitmap bounds is harmless).
// Old code (prior to v15.2.4): rect enlarged to avoid unpainted right/bottom edges
ImageEnView1.IEBitmap.IECanvas.GradientFillRect( Rect( 10, 10, 110 + 1, 60 + 1 ), clYellow, clRed, gpgVertical );

// New code: fills the 100 x 50 area from (10, 10)
ImageEnView1.IEBitmap.IECanvas.GradientFillRect( Rect( 10, 10, 110, 60 ), clYellow, clRed, gpgVertical );