Results 1 to 3 of 3

Thread: Unable to read png image

  1. #1
    Join Date
    Feb 2015
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Unable to read png image

    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

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Unable to read png image

    (1) Check whether the image is valid (or does not contain some "extras" in formatting).
    (2) Try
    Qt Code:
    1. QString file = "D:/a.png";
    To copy to clipboard, switch view to plain text mode 
    even if you are in winblows. (Low possibility of success, the file seems to have been found.)
    (3) Try
    Qt Code:
    1. QImage image("D:/a.png");
    To copy to clipboard, switch view to plain text mode 
    and check whether you have loaded something: image.isNull() should be false.
    (4) Try
    Qt Code:
    1. QImage image("D:/a.png","PNG"); // and check image.isNull()
    To copy to clipboard, switch view to plain text mode 

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to read png image

    Also make sure the PNG image plugin is available.
    See QImageReader::supportedImageFormats().

    Cheers,
    _

Similar Threads

  1. [SOLVED] Unable to read data by QDataStream
    By karankumar1609 in forum Qt Programming
    Replies: 5
    Last Post: 15th January 2014, 13:54
  2. Replies: 11
    Last Post: 21st June 2011, 01:05
  3. why "Unable to read image data"
    By zarelaky in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 21st December 2010, 00:47
  4. Replies: 3
    Last Post: 18th May 2008, 18:36
  5. Unable to read from QTcpSocket
    By jimroos in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 21:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.