Parcourir la source

load svg from resource

lainz il y a 8 ans
Parent
commit
cb3397685b
3 fichiers modifiés avec 16 ajouts et 2 suppressions
  1. 11 1
      bcsvgviewer.pas
  2. 3 0
      test/test_bcsvg/test_svg.lpi
  3. 2 1
      test/test_bcsvg/umain.pas

+ 11 - 1
bcsvgviewer.pas

@@ -6,7 +6,7 @@ interface
 
 uses
   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, BGRAGraphicControl,
-  BGRABitmap, BGRABitmapTypes, BGRASVG, BGRAUnits;
+  BGRABitmap, BGRABitmapTypes, BGRASVG, BGRAUnits, LCLType;
 
 type
 
@@ -28,6 +28,7 @@ type
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     procedure LoadFromFile(AFileName: string);
+    procedure LoadFromResource(Resource: String);
   published
     { Published declarations }
     property Align;
@@ -127,4 +128,13 @@ begin
   FSVG.LoadFromFile(AFileName);
 end;
 
+procedure TBCSVGViewer.LoadFromResource(Resource: String);
+var
+  res: TResourceStream;
+begin
+  res := TResourceStream.Create(HInstance, Resource, RT_RCDATA);
+  FSVG.LoadFromStream(res);
+  res.Free;
+end;
+
 end.

+ 3 - 0
test/test_bcsvg/test_svg.lpi

@@ -14,6 +14,9 @@
         <DpiAware Value="True/PM"/>
       </XPManifest>
       <Icon Value="0"/>
+      <Resources Count="1">
+        <Resource_0 FileName="01 circle.svg" Type="RCDATA" ResourceName="01 CIRCLE"/>
+      </Resources>
     </General>
     <BuildModes Count="1">
       <Item1 Name="Default" Default="True"/>

+ 2 - 1
test/test_bcsvg/umain.pas

@@ -34,7 +34,8 @@ implementation
 
 procedure TForm1.FormCreate(Sender: TObject);
 begin
-  BCSVGViewer1.LoadFromFile('SVG_Logo.svg');
+  //BCSVGViewer1.LoadFromFile('SVG_Logo.svg');
+  BCSVGViewer1.LoadFromResource('01 CIRCLE');
 end;
 
 procedure TForm1.BCSVGViewer1Redraw(Sender: TObject; Bitmap: TBGRABitmap);