1. 把svg静态字符串写死程序里

image

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Skia, Vcl.Skia, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    SkSvg1: TSkSvg;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
  /// <summary>
  /// 把图片写死在程序里
  /// </summary>
  svgStr = '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1717364678249" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6571" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M0 0h1024v1024H0z" fill="#FFFFFF" fill-opacity="0" p-id="6572"></path><path d="M760.901604 195.216203m5.656854 5.656854l56.568543 56.568542q5.656854 5.656854 0 11.313709l-554.371717 554.371716q-5.656854 5.656854-11.313708 0l-56.568543-56.568542q-5.656854-5.656854 0-11.313709l554.371717-554.371716q5.656854-5.656854 11.313708 0Z" fill="#000000" p-id="6573"></path><path d="M828.783855 760.901627m-5.656854 5.656855l-56.568543 56.568542q-5.656854 5.656854-11.313708 0l-554.371717-554.371716q-5.656854-5.656854 0-11.313709l56.568543-56.568542q5.656854-5.656854 11.313708 0l554.371717 554.371716q5.656854 5.656854 0 11.313709Z" fill="#000000" p-id="6574"></path></svg>';

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  SkSvg1.Svg.Source := svgStr;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SkSvg1.Svg.Source := '';
end;

end.

//这个SkSvg1.Svg.Source 的定义我们看下,父类是这样的
property Source: TSkSvgSource read FSource write SetSource;
//再点击 TSkSvgSource 进去,我们会看到 是 string的一个别名,所以可以直接string赋值
TSkSvgSource = type string;

看下以上代码的效果:

image

2. 动态加载svg图片

image

image

posted on 2024-06-10 16:04  del88  阅读(4)  评论(0编辑  收藏  举报