Skip to main content

SvgImageCollection Class

Stores vector images added by you and provides these images to DevExpress controls.

Namespace: DevExpress.Utils

Assembly: DevExpress.Utils.v24.1.dll

NuGet Packages: DevExpress.Utils, DevExpress.Wpf.Core

Declaration

public class SvgImageCollection :
    ImageCollection<SvgImage, SvgImageInfo>

Remarks

In this document:

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.

svgImageCollection1.ImageSize = new System.Drawing.Size(64, 64);

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.

SvgImageColleciton - Add Images

When images are imported in the collection, you can change their names in Collection Editor. These names are used to access images from code.

You can also switch to the Image Picker’s Font Icons tab and choose from hundreds of icons included in Windows 10/11 icon fonts. Read the following topic for additional information: Font Icon Images.

Font Icon Images -- WinForms Image Picker

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.

SvgImageCollection - Embedded Resource

To add images at design time, use the “From Project References” link in the component smart tag menu.

image

To do this in code, call the static SvgImageCollection.FromResources method to initialize a collection that stores these images. This method requires two parameters:

  • resourceBaseName - a path to the resource file. Note that in C# resource file paths use dots in their names to include sub-folders, while VB.NET resource file paths store the root directory name only.
  • assembly - a related System.Reflection.Assembly.
SvgImageCollection collection = SvgImageCollection.FromResources("WindowsFormsApp1.Images", typeof(Form1).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));

Inheritance

Object
MarshalByRefObject
Component
ImageCollection<SvgImage, DevExpress.Utils.SvgImageInfo>
SvgImageCollection
See Also