Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. Qt SVG Editor: How to resize svg image and save it back in SVG form as a resized image.!
QtWS25 Last Chance

Qt SVG Editor: How to resize svg image and save it back in SVG form as a resized image.!

Scheduled Pinned Locked Moved India
8 Posts 2 Posters 9.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prg1234
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prg1234
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jake007
        wrote on last edited by
        #3

        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


        Code is poetry

        1 Reply Last reply
        0
        • P Offline
          P Offline
          prg1234
          wrote on last edited by
          #4

          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...!

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jake007
            wrote on last edited by
            #5

            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();
            

            }@


            Code is poetry

            1 Reply Last reply
            0
            • P Offline
              P Offline
              prg1234
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                prg1234
                wrote on last edited by
                #7

                @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..:(

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jake007
                  wrote on last edited by
                  #8

                  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


                  Code is poetry

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved