Sign in Join
Wiki copytemporary

SVG Image List: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: SVG Image List

OldNewLine
1+Hi, this is a simple tutorial on how to use SVG Images in our Lazarus applications.
2+
3+## Requirements
4+
5+1\) Install [[BGRABitmap]]
6+
7+2\) Install [[BGRAControls]]
8+
9+(Hint: Use online package manager)
10+
11+## Tutorial
12+
13+In this tutorial we will add an SVG Icon to a TMainMenu.
14+
15+### Create elements
16+
17+1\) Drop a TMainMenu, add some entries like 'File' and a sub entry 'Open'.
18+
19+2\) Drop a regular TImageList, assign it to the MainMenu1 we previously created.
20+
21+3\) Assign the ImageIndex in the entries, for example in the File \> Open add index 0.
22+
23+That is not different as you need to do it anyways with a regular image list, so nothing changes here. The next step shows the SVG stuff.
24+
25+### Create SVG Image List
26+
27+1\) Add a TBGRASVGImageList from BGRA Themes pallete.
28+
29+2\) Double click the SVG Image List component and add some SVG's, just load them from file.
30+
31+3\) Add this code, the glue between our two image lists:
32+
33+``` pascal
34+procedure TForm1.FormCreate(Sender: TObject);
35+begin
36+ BGRASVGImageList1.PopulateImageList(ImageList1, [24]);
37+end;
38+```
39+
40+**Done!**
41+
42+Now you have SVG Icons in your application, repeat for buttons and any component that supports a regular image list.
43+
44+### Optional parameter
45+
46+The second parameter is array of resolutions, 24px is the default on Windows. You can add more like 48px for retina on macOS or High DPI on Windows.
47+
48+``` pascal
49+BGRASVGImageList1.PopulateImageList(ImageList1, [24, 48]);
50+```
51+
52+**Important:** You need to enable 'Scaled' property on the regular image list in order to the extra resolutions work fine.
53+
54+Enjoy!
55+
56+---
57+*From the Free Pascal wiki, page "SVG Image List", as it stood on 2022-08-16 after a change by Skalogryz, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
58+Category: Graphics
59+Category: SVG

Back to history