Results 1 to 20 of 20

Thread: vector image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default vector image

    Hi how can I insert into my graphics scene vector image? QT supports only svg files? or some other files (eps, ps...) too? If yes, so what?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vector image

    Unless you provide an image plugin for reading such files, you'll have to convert them to some supported format.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    Quote Originally Posted by wysota View Post
    Unless you provide an image plugin for reading such files, you'll have to convert them to some supported format.
    could you give me some hint, how to convert to supported format? thanks

    i tried this
    Qt Code:
    1. void MainWindow::loadVectorImage()
    2. {
    3. const QString fileName = QFileDialog::getOpenFileName(this, tr("Select Vector Images"),
    4. QDesktopServices::storageLocation(QDesktopServices::PicturesLocation),
    5. "*.pdf *eps *.ps *.svg");
    6.  
    7. QPicture picture;
    8. if (fileName.isEmpty() || !picture.load(fileName)) return;// loading to image
    9.  
    10. QPixmap imageNew;
    11. QPainter painter;
    12. painter.begin(&imageNew); // paint in imageNew
    13. painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
    14. painter.end();
    15.  
    16.  
    17. // set vector image to scene image into scene
    18. scene->openImage(imageNew);
    19. }
    To copy to clipboard, switch view to plain text mode 
    but it doesnt work

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vector image

    You have to use some application that is able to read your format and write one of supported formats. To see what formats are supported by your installation of Qt, use QImageReader::supportedImageFormats().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    so I should use svg? Because QImageReader::supportedImageFormats() are bitmap file, arent they?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vector image

    At some point you will have to convert your vector image to bitmap anyway, so it's your choice when to do it. If you want to go for svg, that's fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    thanks but I dont know how I should to convert vector image to pixmap...
    when I tried this code (I wrote it in this thread) it doesnot work.
    Then I found thisand Alex answer is similar with my code
    load vector image into QPicture
    Qt Code:
    1. QPicture picture;
    2. picture.load(fileName))
    3. QPixmap imageNew(100, 100);
    4. imageNew.fill();
    5. QPainter painter(&imageNew); // ??? convert to pixmap ???
    6. painter.drawPicture(0, 0, picture);// paint to paniter
    To copy to clipboard, switch view to plain text mode 
    but nothing happens

    edit: so problem could be in "picture.load(fileName)" but I dont know why, I though that QPicture::load it should be ok but it isnot
    Last edited by Noxxik; 10th March 2009 at 23:00.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vector image

    I don't see a point of loading the image to the picture and them immediately trying to put it on a pixmap. You could load it to the pixmap directly. By the way, if you have an svg image, you have to use QSvgRenderer to transfer it to a pixmap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    sorry for my stupid answers, could you help me once again how I should to load a vector image? I thought that I tried to load vector image in QPicture to the pixmap directly.
    svg images dont have to be default, rather I would like to load image in pdf or in eps file

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vector image

    I already told you you can't load a postscript image to Qt applications directly, because neither of these formats are supported. You have to convert your vector image to some other supported format using a 3rd party application such as Gimp or ImageMagick and then load it into Qt. You can also use a 3rd party library (such as poppler for PDF) to do that inside your application. In the end you will have to have a raster representation of the image, regardless if you use PDF, EPS, SVG or PNG. The only thing you can decide is when to do the conversion and what resolution to use in case of vector graphics.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: vector image

    Quote Originally Posted by wysota View Post
    I already told you you can't load a postscript image to Qt applications directly, because neither of these formats are supported. You have to convert your vector image to some other supported format using a 3rd party application such as Gimp or ImageMagick and then load it into Qt. You can also use a 3rd party library (such as poppler for PDF) to do that inside your application. In the end you will have to have a raster representation of the image, regardless if you use PDF, EPS, SVG or PNG. The only thing you can decide is when to do the conversion and what resolution to use in case of vector graphics.
    thanks I am trying poppler library, but it writes me one error, when I try to compile my programme
    my compilor mingw wrote this error
    undefined reference to '_imp___ZN7Poppler8Document4loadERK7QStringRK10QBy teArrayS6_'

    but I dont know where I have mistake

    I wrote this...
    Qt Code:
    1. const QString fileName = QFileDialog::getOpenFileName(this, languages[1],
    2. QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation),
    3. "*.pdf");
    4.  
    5. Poppler::Document *document = Poppler::Document::load(fileName); // this is the error
    6. if (!document/* || document->isLocked()*/) {
    7.  
    8. QMessageBox::information(this, tr("Business Card Generator"), tr("Cannot load %1.").arg(fileName));
    9.  
    10. // delete document;
    11. return;
    12. }
    To copy to clipboard, switch view to plain text mode 
    Do you know where I have mistake please? or what could I have do? please

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.