SvgImageCollection Class
Stores vector images added by you and provides these images to DevExpress controls.
Namespace: DevExpress.Utils
Assembly: DevExpress.Utils.v18.1.dll
Declaration
[ToolboxBitmap(typeof(ToolboxIconsRootNS), "ImageCollection")]
[ToolboxTabName("DX.18.1: Components")]
public class SvgImageCollection :
Component,
IList<SvgImage>,
ICollection<SvgImage>,
IEnumerable<SvgImage>,
IEnumerable,
ISupportInitialize
Related API Members
The following members accept/return SvgImageCollection objects:
Remarks
In this document:
- Default Image Size
- Add Images from Disc, Project Resources or Image Gallery
- Add Images from Assemblies
- Access Images From Code
Other DevExpress image storages
Default Image Size
The SvgImageCollection provides the SvgImageCollection.ImageSize property, which specifies the default image size. If you do not manually specify an image size on a control’s side (the ImageOptions.SvgImageSize property), a vector image has this default size.
Add Images from Disk, Project Resources or Image Gallery
Invoke the component smart tag and click “Edit Collection” to invoke the Collection Editor dialog. Use the “Add” selector to choose where to import SVG images from.
When images are imported in the collection, you can change their names in Collection Editor. These names are used to access images from code.
Add Images from Assemblies
The SvgImageCollection can retrieve vector images from a compiled assembly.
Add a project folder and populate it with icons, then change their Build Action property to EmbeddedResource.
Now call the static SvgImageCollection.FromResources method to initialize a collection that stores these images. This method requires two parameters:
- resourceBaseName - a path to a folder that stores your images (uses dots instead of slashes as path separators).
- assembly - a related System.Reflection.Assembly.
SvgImageCollection collection = SvgImageCollection.FromResources("WindowsFormsApp1.Images", typeof(Form3).Assembly);
Access Images From Code
The SvgImageCollection can return both “real” vector images (by accessing images directly using indexers or image names), and regular raster images produced from vector ones (by calling the SvgImageCollection.GetImage method). Note that the GetImage method provides overloads with and without the “palette” parameter. If you use the overload without this parameter, the resulting raster image is identical to the source vector image. Otherwise, the raster image is repainted according to the provided palette. See the How To: Draw and Use SVG Images article for details on how to use vector skin palettes to change icons’ colors.
The code below illustrates different methods of how to assign a 164x164-pixel image to a simple button if the source image is stored in the SvgImageCollection.
// access vector images by image names
simpleButton1.ImageOptions.SvgImage = collection["Bold"];
simpleButton1.ImageOptions.SvgImageSize = new System.Drawing.Size(164, 164);
// access vector images by image indexes
simpleButton1.ImageOptions.SvgImage = collection[5];
simpleButton1.ImageOptions.SvgImageSize = new System.Drawing.Size(164, 164);
// access raster images produced from vector images
var palette = SvgPaletteHelper.GetSvgPalette(this.LookAndFeel, DevExpress.Utils.Drawing.ObjectState.Normal);
simpleButton1.ImageOptions.Image = collection.GetImage(5, palette, new System.Drawing.Size(164, 164));
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SvgImageCollection class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.