phoenix_title wx.svg.SVGimage

The SVGimage class provides various ways to load and use SVG images in wxPython applications.


class_hierarchy Class Hierarchy

Inheritance diagram for class SVGimage:

super_classes Known Superclasses

wx.svg._nanosvg.SVGimageBase


method_summary Methods Summary

ConvertToBitmap

Creates a wx.Bitmap containing a rasterized version of the SVG image.

ConvertToScaledBitmap

Automatically scales the SVG image so it will fit in the given size,

RenderToGC

Draw the collection of shapes and paths in the SVG image


api Class API

class SVGimage(SVGimageBase)

The SVGimage class provides various ways to load and use SVG images in wxPython applications.


Methods

ConvertToBitmap(self, tx=0.0, ty=0.0, scale=1.0, width=-1, height=-1, stride=-1)

Creates a wx.Bitmap containing a rasterized version of the SVG image.

Parameters
  • tx (float) – Image horizontal offset (applied after scaling)

  • ty (float) – Image vertical offset (applied after scaling)

  • scale (float) – Image scale

  • width (int) – width of the image to render, defaults to width from the SVG file

  • height (int) – height of the image to render, defaults to height from the SVG file

  • stride (int) – number of bytes per scan line in the destination buffer, typically width * 4

Returns

wx.Bitmap



ConvertToScaledBitmap(self, size, window=None)

Automatically scales the SVG image so it will fit in the given size, and creates a wx.Bitmap of that size, containing a rasterized version of the SVG image. If a window is passed then the size of the bitmap will automatically be adjusted to the content scale factor of that window. For example, if a (32,32) pixel bitmap is requested for a window on a Retina display, then a (64,64) pixel bitmap will be created.

Parameters
  • size (wx.Size) – Size of the bitmap to create, in pixels

  • window (wx.Window) – Adjust the size by this window’s content scale factor, if supported on the platform

Returns

wx.Bitmap



RenderToGC(self, ctx, scale=None, size=None)

Draw the collection of shapes and paths in the SVG image onto the given wx.GraphicsContext using the drawing primitives provided by the context. The Context’s state is saved and restored so any transformations done while rendering the SVG will be undone.

Parameters
  • ctx (wx.GraphicsContext) – The context to draw upon

  • scale (float) – If given, apply to the context’s scale.

  • float) size ((float,) – If given, scale the image’s width and height to that provided in this parameter. Ignored if scale is also specified.

Note

Some GraphicsContext backends perform better than others. The default GDI+ backend on Windows is the most glitchy, but the Direct2D backend works well.