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.



  • Well, Im not talking about zooming image here..Its Resizing to be precise..!



  • Hi!

    You can not scale or rescale svg image in pixels. Svg image is a set of vectors, which calculates on load for given resolution. So in any resolution that you will save, it will be completely the same.

    Hope it makes any sense ;)

    Regrads,
    Jake



  • ok..i got that..!

    But even if i save the contents of graphicsvies..they got stored as pixmap instead svg..!

    with the above code..!

    I want to save the contents as svg only...!



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.