PDA

View Full Version : Loading static images (png, jpeg) using QImage



avinaskpai12
27th March 2020, 06:40
I am using Visual Studio 2015 with 32-bit Qt libraries which i built from qt-everywhere-src-5.12.0. Trying to load a static image using QImage.
Receive the following message when i debug :
QImage not loading, Error : <Information not available, no symbols loaded for Qt5Gui.dll>

I tried the same approach in Qt creator and I am able to load the image.

Have used the following code :



void BqtOglCanvas::drawImage(int width, int height, BmRect imageRect)
{

imgFlag = true;

resultSize = QSize(width, height);
paintRect = QRect(QPoint(imageRect.pnt1.x, imageRect.pnt1.y), QPoint(imageRect.pnt2.x, imageRect.pnt2.y));
}

QImage* BqtOglCanvas::loadImage(const QString &fileName, QImage *image) {

image->load(fileName);

*image = image->scaled(resultSize, Qt::KeepAspectRatio);

return image;
}

QImage BqtOglCanvas::getSourceImage() {
return sourceImage;
}

void BqtOglCanvas::paintEvent(QPaintEvent *e)
{

if (imgFlag) {
imgFlag = false;

QImage sourceImage = getSourceImage();

QImage* img = loadImage("C:/Users/qu826e/Downloads/ply.png", &sourceImage);

const QRect imageRect = paintRect;
const QImage resImage = *img;
QPainter painter(this);
painter.drawImage(imageRect, resImage);
}
}


Any leads will be really helpful.

d_stranz
27th March 2020, 16:31
Receive the following message when i debug :
QImage not loading, Error : <Information not available, no symbols loaded for Qt5Gui.dll>

If you really are running a Debug version of your program, it should be reporting "Qt5GuiD.dll". Be sure you are linking with the correct libraries.

QImage::load() returns a Boolean to indicate whether the load succeeded. Why don't you check it before trying to do anything more?

Are you sure the fileName value points to the correct location on disk? Are you passing an absolute path or a relative path?

Is a "image" a non-null pointer to a QImage? You can't call a class method through a null pointer, and "load" will not create a QImage instance.

avinaskpai12
30th March 2020, 06:55
It's reporting Qt5Guid.dll. Have a doubt regarding the libraries. I built the lib using qt-everywhere-src-5.12.0 using the command : configure -debug -nomake examples -nomake tests -skip qtwebengine –opensource –opengl es2. Does this generate appropriate lib for QImage?

QImage::load() returns a Boolean value true.

fileName value points to the correct location on disk. it as an absolute path.

QImage sourceImage = getSourceImage();
sourceImage comes out to be null.

ChristianEhrlicher
30th March 2020, 17:01
QImage sourceImage = getSourceImage();
sourceImage comes out to be null.


QImage BqtOglCanvas::getSourceImage() {
return sourceImage;
}

Where do you fill this (member) variable?

avinaskpai12
31st March 2020, 10:36
void BqtOglCanvas::drawImage(int width, int height, BmRect imageRect)
{

imgFlag = true;

resultSize = QSize(width, height);
QImage image(resultSize, QImage::Format_RGB32);
sourceImage = image;
paintRect = QRect(QPoint(imageRect.pnt1.x, imageRect.pnt1.y), QPoint(imageRect.pnt2.x, imageRect.pnt2.y));
}


filling the variable in drawImage.

ChristianEhrlicher
31st March 2020, 10:48
You create an empty (uninitialized) image with the size width/height and assign it to sourceImage. Nothing more.

avinaskpai12
1st April 2020, 06:18
can you help me out with the steps to load the image?

d_stranz
1st April 2020, 17:01
It's pretty simple:



QImage image;
if ( image.load( filename ) )
{
// If you get here, the image was loaded successfully and is valid
}
else
{
// If you end up here, something went wrong
}