秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
最新的skia4delphi(6.0)核心单元(System.Skia.pas/System.Skia.API.pas)已适配fpc 3.3.1,只需将vcl.skia.pas移植到lazarus就可以。
https://github.com/skia4delphi/skia4delphi 移植后已可以实现首页上的几个示例。
skia4delphi for lazarus安装包:

链接:https://pan.baidu.com/s/1juw4xlV_ILyNdGcoOP0cZw?pwd=n9lg
提取码:n9lg
控件安装:
skia4delphi\packages\lazarus\skia.package.lcl.lpk
注意事项:
1、安装前将sk4d.dll拷贝到lazarus.exe的文件夹,否则控件安装完成后lazarus启动不了。
2、FPC 3.3.1
3、应用分发时需要带sk4.dll

 

 

控件安装后:

 Demo下载:

链接:https://pan.baidu.com/s/1wQ3TyXHE6jX52JU39nEDlA?pwd=wrii
提取码:wrii

unit Unit1;

{$mode delphi}//{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  types, System.Skia, Lcl.Skia,System.UITypes,System.IOUtils,LConvEncoding;

type

  { TForm1 }
  TSkDrawExampleProc = reference to procedure(const ACanvas: ISkCanvas; const ADest: TRectF);

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure SkPaintBox1Draw(ASender: TObject; const ACanvas: ISkCanvas;
      const ADest: TRectF; const AOpacity: Single);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }


procedure DrawExample(const AWidth, AHeight: Integer; const ADrawProc: TSkDrawExampleProc);
var LSurface : ISkSurface;
begin
  LSurface := TSkSurface.MakeRaster(AWidth, AHeight);
  LSurface.Canvas.Clear(TAlphaColors.Null);
  ADrawProc(LSurface.Canvas, RectF(0, 0, AWidth, AHeight));
  LSurface.MakeImageSnapshot.EncodeToFile('output.png');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
LPaint:ISkPaint;
LRect : TRectF;
LOval: ISkRoundRect;
begin
  DrawExample(256, 256,
    procedure (const ACanvas: ISkCanvas; const ADest: TRectF)
    begin
      LPaint := TSkPaint.Create;
      //ISkPaint := TSkPaint.Create;
      LPaint.AntiAlias := True;

      LPaint.Color := $FF4285F4;
      LRect := TRectF.Create(PointF(10, 10), 100, 160);
      ACanvas.DrawRect(LRect, LPaint);

      LOval := TSkRoundRect.Create;
      LOval.SetOval(LRect);
      LOval.Offset(40, 80);
      LPaint.Color := $FFDB4437;
      ACanvas.DrawRoundRect(LOval, LPaint);

      LPaint.Color := $FF0F9D58;
      ACanvas.DrawCircle(180, 50, 25, LPaint);

      LRect.Offset(80, 50);
      LPaint.Color := $FFF4B400;
      LPaint.Style := TSkPaintStyle.Stroke;
      LPaint.StrokeWidth := 4;
      ACanvas.DrawRoundRect(LRect, 10, 10, LPaint);
    end);
end;

procedure TForm1.SkPaintBox1Draw(ASender: TObject; const ACanvas: ISkCanvas;
  const ADest: TRectF; const AOpacity: Single);
var LPaint: ISkPaint;
begin
  LPaint := TSkPaint.Create;
  LPaint.Shader := TSkShader.MakeGradientSweep(ADest.CenterPoint,
    [$FFFCE68D, $FFF7CAA5, $FF2EBBC1, $FFFCE68D]);
  ACanvas.DrawPaint(LPaint);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
    LBitmap : TBitmap;
    LImage : ISkImage;
    sp: TSkPaintBox;
    LLabel:TSkLabel;
    LSvg : TSkSvg;
    s:string;
    svg:TStringlist;
    b:TSkSvgWrapMode;
begin
    LImage := TSkImage.MakeFromEncodedFile('output.png');
    LImage.EncodeToFile('output.webp', TSkEncodedImageFormat.WEBP, 80);
    LImage.EncodeToFile('output.jpg', TSkEncodedImageFormat.JPEG, 80);

    LLabel:=TSkLabel.Create(panel1);
    LLabel.Caption:='skia Lazarus TSkLabel测试';
    LLabel.SetBounds(0, 0, panel1.Width, panel1.Height);
    //LLabel.AlignWithMargins := True;
    LLabel.TextSettings.MaxLines := 4;
    LLabel.Align := alClient;//alLeft;
    LLabel.TextSettings.Font.Size := 32;
    LLabel.TextSettings.HorzAlign:=TSkTextHorzAlign.Center;
    LLabel.TextSettings.VertAlign:=TSkTextVertAlign.Center;
    LLabel.TextSettings.Font.Weight := TSkFontComponent.TSkFontWeight.Medium;
    LLabel.TextSettings.FontColor :=$FF2EBBC1;// $FFA0A0A1;
    LLabel.Parent := panel1;

    sp:= TSkPaintbox.Create(panel2);
    sp.SetBounds(0,0,panel2.Width,panel2.Height);
    sp.Parent:=panel2;
    sp.OnDraw:=SkPaintBox1Draw;

    LSvg := TSkSvg.Create(panel3);
    svg:=TStringlist.Create;
    svg.LoadFromFile('panda.svg');
    LSvg.SetBounds(0,0,panel3.Width,panel3.Height);
    LSvg.Svg.WrapMode:=TSkSvgWrapMode.Fit;
    LSvg.Svg.Source:=svg.Text;
    LSvg.Parent := panel3;
    svg.Free;
end;

end.

  

 

posted on 2024-01-30 10:41  秋·风  阅读(326)  评论(3编辑  收藏  举报