lazarus开发:显示SVG图像

 

用简短的代码显示SVG图像。

lazarus开发:显示SVG图像_第1张图片

代码:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  BGRABitmap, BGRABitmapTypes, BGRAVirtualScreen, BGRACanvas2D;

type

  { TForm1 }

  TForm1 = class(TForm)
    Timer1: TTimer;
    VirtualScreen: TBGRAVirtualScreen;
    procedure VirtualScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
  private
    procedure Test5(ctx: TBGRACanvas2D);

  public

  end;

var
  Form1: TForm1;

implementation

uses BGRASVG;

{$R *.frm}

{ TForm1 }

procedure TForm1.VirtualScreenRedraw(Sender: TObject; Bitmap: TBGRABitmap);
var ctx: TBGRACanvas2D;
begin

  ctx := Bitmap.Canvas2D;
  ctx.antialiasing := true;
  ctx.pixelCenteredCoordinates := true;
  ctx.save;

  Test5(ctx);
  ctx.restore;
end;


procedure TForm1.Test5(ctx: TBGRACanvas2D);
var svg: TBGRASVG;
begin

  svg := TBGRASVG.Create;
  svg.LoadFromFile(extractFilePath(ParamStr(0)) +'lazarus.svg');
  svg.StretchDraw(ctx, taCenter,tlCenter, 0,0, ctx.Width, ctx.Height);
end;

end.

 

 

你可能感兴趣的:(Lazarus,lazarus,svg)