PDA

View Full Version : Unable to read png image



sriprabha
21st February 2015, 07:07
Hi,
I'm a newbie in Qt.
I'm trying to read a png image from disk.
But load return false. The image size is around 350x250 and OS is windows. I'm using qt 4.8.4 built in 64bit, debug mode.
The programming environment is Visual Studio 2010.
I tried following options

QString file = "D:\\a.png";
QFileInfo fileInfo(file);
bool fileValid = fileInfo.exists(); // this gives true

QImage image;
bool loadStat = image.load(file); // this returns false

QPixmap imgPix;
bool pixStat = imgPix.load(file); // this returns false

QImageReader *imageRead = new QImageReader(file);
bool readstat = imageRead->canRead(); //this also false

I'm not sure what this wrong. I want to read this image and print it.
Any suggestions?

Thanks,
R.Sriprabha

Radek
22nd February 2015, 10:36
(1) Check whether the image is valid (or does not contain some "extras" in formatting).
(2) Try


QString file = "D:/a.png";

even if you are in winblows. (Low possibility of success, the file seems to have been found.)
(3) Try


QImage image("D:/a.png");

and check whether you have loaded something: image.isNull() should be false.
(4) Try


QImage image("D:/a.png","PNG"); // and check image.isNull()


My guess is (1). The image should load by your code. Loading .png does not need any extra modules to load. Also try to load some other image, which is .png rather surely. For example, download some .png icon from somewhere.

anda_skoa
2nd March 2015, 12:12
Also make sure the PNG image plugin is available.
See QImageReader::supportedImageFormats().

Cheers,
_