Results 1 to 2 of 2

Thread: loading image from disk

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default loading image from disk

    I'm trying to load an image file from disk and I would like to draw the same image along with a rectangle whose size is updated using spin boxes. However, I couldn't load the image. I'm using this code:

    Qt Code:
    1. QImage img("/c/documents and settings/usr/desktop/c++/qt/experiments/boundary/sample.jpg",0)
    2. QPixmap pixmap = QPixmap::fromImage(image);
    To copy to clipboard, switch view to plain text mode 

    The image file is named as sample.jpg. Thanks for the help.

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: loading image from disk

    hi
    QImage img("/c/documents and settings/usr/desktop/c++/qt/experiments/boundary/sample.jpg",0);
    the path specified is wrong.
    try
    Qt Code:
    1. QImage img("c:\documents and settings\usr\desktop\c++\qt\experiments\boundary\sample.jpg",0);
    To copy to clipboard, switch view to plain text mode 

    or try
    Qt Code:
    1. QImage img("c:\\documents and settings\\usr\\desktop\\c++\\qt\experiments\\boundary\\sample.jpg",0);
    To copy to clipboard, switch view to plain text mode 

    however u can directly load image in QPixmap
    Qt Code:
    1. QPixmap *img=new QPixmap("c:\documents and settings\usr\desktop\c++\qt\experiments\boundary\sample.jpg");
    To copy to clipboard, switch view to plain text mode 


    hope it helps
    Bala
    Last edited by BalaQT; 18th February 2010 at 05:25.

  3. The following user says thank you to BalaQT for this useful post:

    freekill (18th February 2010)

Similar Threads

  1. problems loading an image .jpg
    By maider in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2009, 11:57
  2. Image Loading
    By kavinsiva in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 08:00
  3. Need your help... loading image on my widgetstack page..
    By megabeat in forum Qt Programming
    Replies: 4
    Last Post: 30th January 2007, 14:00
  4. Create Mountable Disk Image on intel Mac
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2007, 10:09
  5. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16

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.