SVG Icons in wxWidgets C++

By the Axialis Engineering team ·

SVG Icons in wxWidgets C++

Shipping one PNG per icon per DPI bloats your wxWidgets binary and still looks soft on 150% and 200% displays. This guide replaces those PNGs with a single SVG per icon: you load it through wxBitmapBundle::FromSVG or wxBitmapBundle::FromSVGFile, request a wxBitmap at the size and scale your UI needs, and draw it crisply at any DPI, starting from a clean SVG exported with Axialis IconVectors.

The SVG file is parsed once by wxBitmapBundle and rasterized at the pixel size each display scale needs, then handed to the toolkit as wxBitmap on demand icon.svgone sourcewxBitmapBundleFromSVG / FromSVGFileparses the vector oncepaths, fills, strokesrasterize at the target size16 pxat 100%24 pxat 150%32 pxat 200%wxBitmap on demandthe bundle rasterizes per DPIcrisp at 1x, 2x, 3xwhole-pixel sizes onlyNanoSVG subset insideRender on demand for the DPI the window actually has; never scale a bitmap that was drawn for another one.
Vector in, pixels out, at the right moment. wxBitmapBundle parses the file once; you ask for a bitmap at the size the current display scale needs, 16 px at 100 percent, 24 at 150, 32 at 200, and hand the result to the toolkit as wxBitmap on demand. The bundle keeps the vector and rasterizes it when a control asks for a size, so one SVG serves every DPI the window moves through.

How wxWidgets handles SVG

Export a clean SVG from IconVectors

NanoSVG renders simple geometry reliably, so start from an icon built for that constraint:

  1. A single-color icon open on the IconVectors canvas, ready to export as minified SVG
    A clean, single-color icon on the IconVectors canvas before exporting minified SVG.

Option A — Inline SVG (wxString) to wxBitmap with wxBitmapBundle::FromSVG

Embedding the SVG as a string compiles the icon into your binary, so there is no file to ship or path to resolve at runtime. Pass the markup to wxBitmapBundle::FromSVG() to build a scalable bundle, request a wxBitmap at your target size, and draw it in a paint handler.

#include <wx/wx.h>

static const char kSvg[] = R"SVG(
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" 
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" 
stroke-miterlimit="10" d="M14.8 3.4l1.9 2.3c.2 .2 .5 .4 .8 .4H20c1.1 0 2 .9 2 
2v10c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V8c0-1.1 .9-2 2-2h2.5c.3 0 .6-.1 .8-.4l1.9-2.3
c.2-.2 .5-.4 .8-.4h4.1C14.3 3 14.6 3.1 14.8 3.4zM8.5 12.5c0 1.9 1.6 3.5 3.5 3.5
s3.5-1.6 3.5-3.5s-1.6-3.5-3.5-3.5S8.5 10.6 8.5 12.5z"/></svg>
)SVG";

class MyApp : public wxApp {
public:
  bool OnInit() override {
    auto* frame = new wxFrame(nullptr, wxID_ANY, "SVG in wxWidgets (FromSVG)", wxDefaultPosition, wxSize(260,180));

    // Build a scalable bundle from an in-memory SVG
    wxBitmapBundle bundle = wxBitmapBundle::FromSVG(kSvg, wxSize(24,24));
    wxBitmap bmp = bundle.GetBitmapFor(wxSize(24,24)); // request target size

    frame->Bind(wxEVT_PAINT, [frame, bmp](wxPaintEvent&){
      wxPaintDC dc(frame);
      dc.DrawBitmap(bmp, 40, 40, /*useMask=*/true);
    });

    frame->Show();
    return true;
  }
};
wxIMPLEMENT_APP(MyApp);

Tip: For HiDPI, compute the target size with frame->FromDIP(wxSize(24,24)) before calling GetBitmapFor().

Option B — External file to wxBitmap with wxBitmapBundle::FromSVGFile

Loading from disk keeps icons swappable without recompiling, which suits themeable or pluggable UIs. Point wxBitmapBundle::FromSVGFile() at a packaged file such as icons/check.svg, request the wxBitmap, and draw it the same way.

#include <wx/wx.h>

class MyApp : public wxApp {
public:
  bool OnInit() override {
    auto* frame = new wxFrame(nullptr, wxID_ANY, "SVG in wxWidgets (FromSVGFile)", wxDefaultPosition, wxSize(260,180));

    wxString path = wxT("icons/check.svg");
    wxBitmapBundle bundle = wxBitmapBundle::FromSVGFile(path, wxSize(24,24));
    wxBitmap bmp = bundle.GetBitmapFor(wxSize(24,24));

    frame->Bind(wxEVT_PAINT, [frame, bmp](wxPaintEvent&){
      wxPaintDC dc(frame);
      dc.DrawBitmap(bmp, 40, 40, /*useMask=*/true);
    });

    frame->Show();
    return true;
  }
};
wxIMPLEMENT_APP(MyApp);

Using the bitmap in controls

Notes and troubleshooting

Related guides

Start Making SVG Icons Today with IconVectors

Download the fully-functional 30‑Day Free Trial and unlock your icon design workflow.

Version 2.10 for Windows - October 6, 2026. macOS and Linux: version 2.00 available now, 2.10 coming soon.