Results 1 to 6 of 6

Thread: Loading an Image into QImage

  1. #1
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Loading an Image into QImage

    I have been trying to load an image into QImage. The original image is a "tif", so I converted to a pnm format (supported by QT). I then call up up the following code

    Qt Code:
    1. QString fileName = "<FileName>";
    2. QImage Image = QImage(fileName,"PNM");
    3. int width = Image.width();
    4. QVariant wid = width
    5. debugLineEdit->setText(wid.toString());
    To copy to clipboard, switch view to plain text mode 

    The width comes out as 0. So I used the

    bool Qimage::load() to verify if the image was loading and it is false. Does anyone have any idea why I wouldn't be able to load a PNM Image. Otherwise, if anyone knows a better way to access the information from a TIF format?

    Thank you guys

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Loading an Image into QImage

    One of the most common problems in such cases is the fileName resolution.
    Usually problems with the wrong path.
    You can test that with QFileInfoIf the fileName is not the problem, the next is to make sure the conversion from tif to pnm is a successful one.
    So try to open the converted image with a viewer that can open pnm images and see its valid.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Loading an Image into QImage

    What version are you working with? Qt 4.7 doesn't support PNM files. It does support TIFF files, though, so perhaps you should try loading the original image instead.

    See here: http://doc.qt.nokia.com/4.7/qimagere...edImageFormats
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

  4. #4
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading an Image into QImage

    Thank you guys for taking the time to help me out. Currently, I am stuck with QT 3.3.6. However, I think they should be upgrading sometime soon to a QT 4. Don't know if it will be a 4.7 though.

    -high_flyer
    I thought this could have been the issue so I hard coded the process to a single file that I knew existed and was able to open up using a linux image viewing utility. The file shows up in the image viewer as a PNM file. It says it supports the format listed as PNM in the QT documentation. Unfortunately, I don't have any control over the version of QT I am using ( that would be too easy then). The picture is a 16bit grayscale image that I convert to PNM using the tifftopnm method of the netpbm program from Unix. I don't know if any of this will help out but all the evidence is pointing to the fact that the conversion was successful.

    One quick question, In my previous code when I specify "PNM" as the image format. Do I need to specify the type of PNM. Or is my syntax correct?
    From QT ImageI/O documentation
    The different PNM formats are: PBM (P1 or P4), PGM (P2 or P5), and PPM (P3 or P6).
    Last edited by jstippey; 4th January 2011 at 13:22.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Loading an Image into QImage

    [sh*** delete by mistake...]
    P.S
    At worse, you will need to implement your own conversion, but if I am not mistaking the PNM formats are text based, this should be rather easy to do.
    Last edited by high_flyer; 4th January 2011 at 13:40.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. The following user says thank you to high_flyer for this useful post:

    jstippey (4th January 2011)

  7. #6
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading an Image into QImage

    Thanks everyone for your help. Using the QFileInfo, I found that I could see the file. The issue was that I could not specify "PNM", when doing the Image input format of PNM you should specify whether it is PBM, PGM, or PPM.

Similar Threads

  1. Loading corrupt jpeg images with QImage
    By mikeee7 in forum Qt Programming
    Replies: 15
    Last Post: 3rd December 2010, 01:59
  2. Loading a raw image into QImage
    By Luc4 in forum Qt Programming
    Replies: 6
    Last Post: 16th May 2010, 15:20
  3. problems loading an image .jpg
    By maider in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2009, 11:57
  4. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 08:00
  5. QImage not loading successively.
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2008, 13:20

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.