ImageEn, unit iegdiplus

TIECanvas.Pen

TIECanvas.Pen

Declaration

property Pen: TIEPen;

Description

Provides access to the drawing pen.

Examples

// Draw an anti-aliased ellipse onto a TBitmap
cv := TIECanvas.Create( ABitmap.Canvas );
cv.Pen.Style := psSolid;
cv.Pen.Width := 3;
cv.Pen.Mode  := pmCopy;
cv.Pen.Color := clRed;
cv.Brush.Style := bsClear;
cv.Ellipse( Rect( 100, 100, 200, 200 ));
cv.Free();



// Draw an anti-aliased ellipse onto a TIEBitmap
with iebmp.IECanvas do
begin
  Pen.Style := psSolid;
  Pen.Mode  := pmCopy;
  Pen.Color := clRed;
  Brush.Style := bsClear
  Ellipse( Rect( 100, 100, 200, 200 ));
end;


// Draw a 5-pointed star
var
  pp: array[0..10] of TPoint;
begin
  ImageEnView1.IEBitmap.IECanvas.Pen.Color := clOrangeRed;
  ImageEnView1.IEBitmap.IECanvas.Pen.Width := 3;

  pp[0]  := Point(175, 50);
  pp[1]  := Point(205, 145);
  pp[2]  := Point(300, 145);
  pp[3]  := Point(225, 205);
  pp[4]  := Point(253, 300);
  pp[5]  := Point(175, 243);
  pp[6]  := Point(98 , 300);
  pp[7]  := Point(128, 205);
  pp[8]  := Point(50 , 145);
  pp[9]  := Point(148, 145);
  pp[10] := Point(175, 50);

  ImageEnView1.IEBitmap.IECanvas.Polyline(pp);
  ImageEnView1.Update();
end;



// Draw an envelope with 50% transparency
with ImageEnView1.IEBitmap.IECanvas do
begin
  Pen.Mode  := pmCopy;
  Pen.Style := psSolid;
  Pen.Color := clBlack;
  Pen.Transparency := 128;

  Brush.Color := clYellow;
  Brush.Style := bsSolid;
  Brush.Transparency := 128;

  // Draw outer rect
  Rectangle( 100, 100, 500, 300 );

  // Draw flap
  MoveTo( 100, 100 );
  LineTo( 300, 200 );
  LineTo( 500, 100 );
end;
ImageEnView1.Update();



// Draw a semi-transparent text box onto a bitmap
const
  Horz_Margin = 8;
  Vert_Margin = 3;
  Center_Text = False;
var
  x, y: Integer;
  tw, rw, rh: Integer;
  iec: TIECanvas;
  ss: string;
begin
  ss := 'This is my text';
  x := 100;
  y := 100;

  iec := TIECanvas.Create( Bitmap.Canvas );
  iec.Font.Size := 30;
  iec.Font.Style := [fsBold];

  tw := iec.TextWidth( ss );
  rw := imax( tw + 2 * Horz_Margin, iec.TextWidth( ss ) + 2 * Horz_Margin );
  rh := iec.TextHeight( ss ) + 2 * Vert_Margin;

  if Center_Text then
    Dec( x, rw div 2 );

  iec.Brush.Color := clYellow;
  iec.Brush.Style := bsSolid;
  iec.Brush.Transparency := 196;

  iec.Pen.Color := clBlack;
  iec.Pen.Style := psSolid;
  iec.Rectangle( x, y, x + rw, y + rh );

  iec.Brush.Style := bsClear;
  iec.DrawText( ss, x + ( rw - tw ) div 2, y + Vert_Margin );
  iec.Free();
end;



// Draw a custom rounded, semi-transparent scrollbar
const
  RX         = 12;  // round width
  RY         = 12;  // round height
  MINSLIDERW = 8;   // minimum slider width
var
  scrollPos, scrollCount: Integer;
  sliderWidth: Double;
  x, y, Width, Height: Integer;
begin
  x := 100;
  y := 100;
  Width  := 300;
  Height := 16;
  scrollCount := 20;
  scrollPos := 3;

  with ImageEnView1.IEBitmap.IECanvas do
  begin
    // paint brush and border
    Brush.Style := bsSolid;
    Brush.Color := clWhite;
    Brush.Transparency := 64;
    Pen.Color := clWhite;
    Pen.Style := psSolid;
    Pen.Mode := pmCopy;
    Pen.Width := 1;
    Pen.Transparency := 128;
    RoundRect( x, y, x + width, y + height, RX, RY );

    // paint slider
    Brush.Style := bsSolid;
    Brush.Color := clBlack;
    Brush.Transparency := 128;
    Pen.Width := 1;
    Pen.Transparency := 128;
    sliderWidth := width / scrollCount;
    if sliderWidth < MINSLIDERW then
      sliderWidth := MINSLIDERW;
    RoundRect( x + Trunc(scrollPos * sliderWidth), y + 1, x + Trunc(scrollPos * sliderWidth) + Trunc(sliderWidth), y + height - 1, RX, RY);
  end;
  ImageEnView1.Update();
end;