Qt SVG Editor: How to resize svg image and save it back in SVG form as a resized image.!
-
I can load svg file and render it on QGraphicsView..but how to resize image and store it back in svg..!
I tried following code for saving but it saves the contents as pixmap..!
@QSvgGenerator generator;
generator.setFileName(path);
generator.setSize(QSize(200, 200));QPainter painter(&generator); scene->render(&painter, QRectF(0, 0, 200, 200));
@
But its not working.
-
-
Can you edit svg image in your program?
If you can not, there is no need to re-save it.Otherwise, if you took a look at Svg Generator Example, this is how you save it:
@ void Window::saveSvg()
{
QString newPath = QFileDialog::getSaveFileName(this, tr("Save SVG"),
path, tr("SVG files (*.svg)"));if (newPath.isEmpty()) return; path = newPath; QSvgGenerator generator; generator.setFileName(path); generator.setSize(QSize(200, 200)); generator.setViewBox(QRect(0, 0, 200, 200)); generator.setTitle(tr("SVG Generator Example Drawing")); generator.setDescription(tr("An SVG drawing created by the SVG Generator " "Example provided with Qt.")); QPainter painter; painter.begin(&generator); displayWidget->paint(painter); painter.end();
}@
-
I cant exactly say I can edit my image..but i was trying to display multiple images on the same view..and i succeeded too..!
But I couldn't save this scene as a one svg image .
Its getting saved in svg format with my above code but the contents of it are displayed as pixmap only. -
@void MainWindow::on_actionSave_As_triggered()
{QString newPath = QFileDialog::getSaveFileName(this, tr("Save SVG"), path, tr("SVG files (*.svg)")); if (newPath.isEmpty()) return; path = newPath; QSvgGenerator generator; generator.setFileName(path); generator.setSize(QSize(200, 200)); QPainter painter(&generator); scene->render(&painter, QRectF(0, 0, 200, 200));
}@
I used this code..!
And your previous code contains seperate class to be constructed and function paint..!
Well i dont want that..
M wondering what to write betn..
@ QPainter painter;
painter.begin(&generator);
,,,,,...??
painter.end();@for fun i treied scene.render(painter);
and it worked but again contents were pixmap..:(
-
Have you ever took a look at SVG file how it's written?
It's an xml file.
So one solution would be: read image by image as xml and save required data into a string.
When you are finished gathering data, you only write generated string into an xml file.And a quick tutorial on svg "here":http://www.w3schools.com/svg/default.asp
Regards,
Jake