Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    India
    2
    8
    8176
    Loading More Posts
    • 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
      prg1234 last edited by

      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 Reply Quote 0
      • P
        prg1234 last edited by

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

        1 Reply Last reply Reply Quote 0
        • J
          Jake007 last edited by

          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 Reply Quote 0
          • P
            prg1234 last edited by

            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 Reply Quote 0
            • J
              Jake007 last edited by

              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 Reply Quote 0
              • P
                prg1234 last edited by

                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 Reply Quote 0
                • P
                  prg1234 last edited by

                  @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 Reply Quote 0
                  • J
                    Jake007 last edited by

                    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 Reply Quote 0
                    • First post
                      Last post