Results 1 to 5 of 5

Thread: Creating QImage of specified size from qpic

  1. #1
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Thumbs up Creating QImage of specified size from qpic

    Hi all,

    I have a .pic file created using QPicture. Now I want to create a QImage of that with specified size. Or, atleast it should be possible for me to display the pic with specified size.
    I tried :
    QImage image;
    QImageReader *imageReader = new QImageReader("abc.pic");
    imageReader->setScaledSize(QSize(j,j));
    image = imageReader->read();

    but if i draw this QImage it is not displaying anything.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating QImage of specified size from qpic

    try to use QPicture::load.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Default Re: Creating QImage of specified size from qpic

    But, in QPicture::load we cant pass the size.

    Is it possible to create a QImage of a pic file ??
    Any idea about how to do it ??

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating QImage of specified size from qpic

    why are you using this "pic" format? this format isnt even supported by QImageReader. Either you use a format that is supported by QImageReader or you write your own image format plugin using QPictureFormatPlugin/QImageIOPlugin. The former approach is much better of course.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating QImage of specified size from qpic

    try this
    Qt Code:
    1. QPicture picture;
    2. QPainter painter;
    3. painter.begin(&picture); // paint in picture
    4. painter.drawEllipse(0,0, 80,70); // draw an ellipse
    5. painter.end(); // painting done
    6. picture.save("drawing.pic");
    7.  
    8. picture.load("drawing.pic");
    9.  
    10. QPixmap pixmap(picture.boundingRect().size());
    11. painter.begin(&pixmap);
    12. painter.drawPicture(0, 0, picture);
    13. painter.end();
    14.  
    15. pixmap.save("drawing_not_scaled.png", "PNG");
    16. pixmap = pixmap.scaled(200, 200);
    17. pixmap.save("drawing_scaled.png", "PNG");
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 18:57
  2. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 23:22
  3. Creating a QImage from uchar* data
    By forrestfsu in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 16:21
  4. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14

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.