Page 1 of 1

[wxSVG] Centering an Image

Posted: Sun Dec 02, 2012 8:39 pm
by Deluge
Anyone familiar with wxSVG? I can't figure out how to center the image of a wxSVGCtrl. It always renders in the top-left corner. I've found some documentation here: http://wxsvg.sourcearchive.com/document ... GCtrl.html

I thought that if I could get hold of the underlying wxBitmap I could center it on its parent, but the bitmap image (m_buffer) is protected and I can't access it. And I don't see any public functions that would allow me to access it.

I've tried accesing the wxSVGDocument as well. But I can't see anything from there that would allow me to center the image.

----- Edit

What is it that I need to center? The wxSVGDocument, the wxBitmap, the wxSVGMatrix, ...?

Re: [wxSVG] Centering an Image

Posted: Fri Jun 21, 2019 4:07 am
by Deluge
This is very old. But I recently started working on an old project & found an answer. The method that I used for centering an SVG image with wxSVG is to create a wxSVGDocument then render it to a wxImage & load it into a wxStaticBitmap:

Code: Select all

wxString filename = "example.svg";
wxSVGDocument* svgdoc = new wxSVGDocument();
svgdoc->Load(filename);
wxImage image = svgdoc->Render();
wxStaticBitmap* bitmap = new wxStaticBitmap();
bitmap->SetBitmap(wxBitmap(image));
Then I can position the wxStaticBitmap how I want.