Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: How to create my own QPixmap Or QImage

  1. #1
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default How to create my own QPixmap Or QImage

    Hi,

    I want create my own QPixmap or QImage using my own data. so that I able to set this QPixmap to QLabel instead of drawing the same content again and again in paintEvent()

    Thanks & Regards

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create my own QPixmap Or QImage

    Qt Code:
    1. QPixmap pix;
    2. QPainter p(&pix);
    3. p.drawXYZ();
    4.  
    5. lablel->setPixmap(pix);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 333 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create my own QPixmap Or QImage

    Quote Originally Posted by MrDeath View Post
    Qt Code:
    1. QPixmap pix;
    2. QPainter p(&pix);
    3. p.drawXYZ();
    4.  
    5. lablel->setPixmap(pix);
    To copy to clipboard, switch view to plain text mode 
    One mistake.. always specify a size for the pixmap / image while creating it.
    Something like - QPixmap pix(600,480);
    You cannot paint on null pixmap !!

  4. #4
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    I have tried this code but it is not working.


    Added after 55 minutes:


    Hi,

    Again i tried but it doesn't work. Can you give me small code so that I can get help from it.
    Last edited by sagirahmed; 27th October 2010 at 08:29.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to create my own QPixmap Or QImage

    What have you tried? Show us your code.

  6. #6
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Qt Code:
    1. void DrawImage()
    2. {
    3. QPixmap pix(700,700);
    4. QPainter painter(&pix);
    5. painter.drawText(QPoint(0 ,0),"text");
    6. painter.save();
    7. labelPixmap->setPixmap(pix);
    8. }
    To copy to clipboard, switch view to plain text mode 

    This is my code that I have written. It show some garbage color on Label. Not showing the text
    Last edited by wysota; 27th October 2010 at 10:38. Reason: missing [code] tags

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to create my own QPixmap Or QImage

    First we have [CODE]-tags. Second
    Qt Code:
    1. painter.save();
    To copy to clipboard, switch view to plain text mode 
    is nonsense here! Third read the documentation about QPainter::drawText() especially what the point is defining. And forth: You might want to fill the pixmap with a color first because it is initialized with no specific value.

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create my own QPixmap Or QImage

    Quote Originally Posted by aamer4yu View Post
    One mistake..
    That was not a mistake. That was left as an exercise for the reader.

    always specify a size for the pixmap / image while creating it.
    Something like - QPixmap pix(600,480);
    You cannot paint on null pixmap !!
    You PASSED!!

  9. #9
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    Thanks I am successfully drawn the image using QPainter and set this image to Qlabel.

    Thanks & Regards

  10. #10
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    I want to create a large QPixmap. The size of QPixmap pix(741,2000000). It cause crashing when we execute the code is

    QPixmap pix(741,2000000);
    QPainter painter(&pix);
    QColor clrbg(144,204,114);
    pix.fill(clrbg); /// it crash at this point

    So help me for creating very large pixmap

  11. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to create my own QPixmap Or QImage

    If you are not using the [CODE] tags I won't help you!

  12. #12
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    I want to create a large QPixmap. The size of QPixmap pix(741,2000000). It cause crashing when we execute the code is

    QPixmap pix(741,2000000);
    QPainter painter(&pix);
    QColor clrbg(144,204,114);
    pix.fill(clrbg); /// it crash at this point
    So help me for creating very large pixmap

  13. #13
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 333 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create my own QPixmap Or QImage

    741 * 2000000 = 1482000000 pixels
    Considering 32 bit per pixel
    741 * 2000000 * 32 bits are required
    ie. 741 * 2000000 * 4 == 5928000000 bytes
    ie 5789062 KB
    ie 5653 MB
    ie 5.5 GB

    Do you even have that much RAM ??? Where do you think the memory will be allocated ?
    Obviously its gonna crash !!

  14. #14
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    So How can I solve this problem. If I have to create QPixmap of this size(741*2000000)

  15. #15
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create my own QPixmap Or QImage

    Quote Originally Posted by sagirahmed View Post
    Hi,

    So How can I solve this problem. If I have to create QPixmap of this size(741*2000000)
    create them in short parts. and store then on to the disk. while reading back just do the reverse.

  16. #16
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    How store short part Qpixmap on to disk. that I have I drawn using QPainter.

  17. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 333 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create my own QPixmap Or QImage

    Am not sure, but you can try this -
    pixmap is a IO device,, so you can use seek() to write to a particular point.
    So use that and try writing smaller rects into the pixmap..

  18. #18
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create my own QPixmap Or QImage

    Be aware that for some picture formats, you can't just load a certain part of it.
    Thus, when you want to save such a large file, you're going to get into trouble at some point. Always save files in managable parts and then create software that can stich those parts together. Look at google maps for example.

  19. #19
    Join Date
    Jul 2010
    Posts
    33
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to create my own QPixmap Or QImage

    Hi,

    so can you suggest me other way to create very large Qpixmap or any other class that will handle this. If I have to create QPixmap of this size(741*2000000)
    I know take very huge amount of memory.

  20. #20
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to create my own QPixmap Or QImage

    I'll give you an extremely powerfull tip:
    Do NOT paint what is NOT on screen.

    Unfortunatly, when you're dealing with jpg files for example, and you want to save a stupendously large file, you WILL get into problems very fast.
    Either use another format that allows you to stream the file to disk or from disk or rethink what you're doing (like splitting up the very large jpg into 10 or 100 smaller jpg's)

Similar Threads

  1. Replies: 5
    Last Post: 17th May 2009, 20:02
  2. drawing on a QPixmap or QImage
    By gren15 in forum Newbie
    Replies: 15
    Last Post: 3rd March 2009, 17:48
  3. DIB to QImage or QPixmap
    By ^NyAw^ in forum Qt Programming
    Replies: 0
    Last Post: 8th August 2008, 20:18
  4. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11
  5. QImage or QPixmap?
    By Dark_Tower in forum Qt Programming
    Replies: 9
    Last Post: 1st April 2006, 17:08

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.