PDA

View Full Version : vector image



Noxxik
10th March 2009, 20:06
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?

wysota
10th March 2009, 20:26
Unless you provide an image plugin for reading such files, you'll have to convert them to some supported format.

Noxxik
10th March 2009, 21:55
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
void MainWindow::loadVectorImage()
{
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select Vector Images"),
QDesktopServices::storageLocation(QDesktopServices ::PicturesLocation),
"*.pdf *eps *.ps *.svg");

QPicture picture;
if (fileName.isEmpty() || !picture.load(fileName)) return;// loading to image

QPixmap imageNew;
QPainter painter;
painter.begin(&imageNew); // paint in imageNew
painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
painter.end();


// set vector image to scene image into scene
scene->openImage(imageNew);
}but it doesnt work :(

wysota
10th March 2009, 21:58
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().

Noxxik
10th March 2009, 22:17
so I should use svg (http://doc.trolltech.com/4.5/qtsvg.html)? Because QImageReader::supportedImageFormats() are bitmap file, arent they?

wysota
10th March 2009, 22:45
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.

Noxxik
10th March 2009, 22:55
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 this (http://lists.trolltech.com/qt-interest/2005-04/msg00617.html)and Alex answer is similar with my code
load vector image into QPicture

QPicture picture;
picture.load(fileName))
QPixmap imageNew(100, 100);
imageNew.fill();
QPainter painter(&imageNew); // ??? convert to pixmap ???
painter.drawPicture(0, 0, picture);// paint to paniterbut 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 :(

wysota
10th March 2009, 23:04
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.

Noxxik
10th March 2009, 23:28
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

wysota
11th March 2009, 10:19
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.

Noxxik
11th March 2009, 14:26
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...

const QString fileName = QFileDialog::getOpenFileName(this, languages[1],
QDesktopServices::storageLocation(QDesktopServices ::DocumentsLocation),
"*.pdf");

Poppler::Document *document = Poppler::Document::load(fileName); // this is the error
if (!document/* || document->isLocked()*/) {

QMessageBox::information(this, tr("Business Card Generator"), tr("Cannot load %1.").arg(fileName));

// delete document;
return;
}
Do you know where I have mistake please? or what could I have do? please

wysota
11th March 2009, 14:37
Did you link against the library?

Noxxik
11th March 2009, 14:49
Did you link against the library?
I think yes... I have at top of file.cpp this...
#include <src/poppler-qt4.h>

in src folder I have all which is in "poppler-0.10.4\qt4\src"

edit: or I should add reference src/poppler-qt4.h to myprogram.pro ?

edit2: or I should add some folder to "Qt\4.4.1\src\3rdparty" or some oter place?

wysota
11th March 2009, 15:54
#include <src/poppler-qt4.h>
This only includes the header file into the compilation unit.


edit: or I should add reference src/poppler-qt4.h to myprogram.pro ?

edit2: or I should add some folder to "Qt\4.4.1\src\3rdparty" or some oter place?
You should add an entry similar to: LIBS+=-lpoppler to your project file and rerun qmake.

Noxxik
11th March 2009, 16:08
So I tried it how you wrote me...
So in programm.pro I have

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
LIBS += -lpoppler
# Input
HEADERS += mainscene.h \
# other *.h file
SOURCES += main.cpp \
# other *.cpp file
RESOURCES += images.qrc
RC_FILE = icon.rc
but mingw wrote me, that it dont find -lpoppler it wrote this:

C:\MinGW\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\ mingw32\bin\ld.exe: cannot find -lpoppler
I dont know where I add some this files

wysota
11th March 2009, 17:33
I didn't say you had to copy exactly what I wrote. Please open QMake docs and see what the LIBS variable does and what to put in it.

Noxxik
11th March 2009, 18:41
so I read this (http://doc.trolltech.com/4.3/qmake-variable-reference.html#libs)but I dont understand very well how to add poppler file to my project :(
if I would add something like this win32:LIBS += c:/mylibs/math.lib in poppler-0.10.4 (http://poppler.freedesktop.org/poppler-0.10.4.tar.gz) I didnt find any lib files or I have to install poppler? I dont know how it install in windows

wysota
11th March 2009, 18:47
Yes, you have to install poppler. You can't use something you don't have.

Noxxik
11th March 2009, 19:11
So I should find some manual how to install in windows, but I cannot find any manual. I tried find something (http://texomaker.les-domlols.com/index.php/en/installation), but instalation in windows it is not so easy

Noxxik
13th March 2009, 09:06
I remove poppler library and I add only svg images. So thank you for help ;)
I send you thanks