Results 1 to 3 of 3

Thread: QGraphicsPixmapItem to QPixmap to QImage and back again!

  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsPixmapItem to QPixmap to QImage and back again!

    I have a giant image cut into tile pieces.

    The tile pieces store a QGraphicsPixmapItem that has been added to a scene.

    On rare occassions, the user may choose to change the color table the image is using.

    When the user chooses to change the colors, I attempt to change the QGraphicsPixmapItem in the following manner:

    image = QGraphicsPixmapItem*
    table = QVector<QRgb> (passed in from a function)

    Qt Code:
    1. QPixmap tempPixmap = image->pixmap();
    2.  
    3. QImage tempImage = tempPixmap.toImage();
    4.  
    5. tempImage.setColorTable( table );
    6.  
    7. tempPixmap = tempPixmap.fromImage( tempImage );
    8.  
    9. image->setPixmap( tempPixmap );
    To copy to clipboard, switch view to plain text mode 

    Now since these Pixmaps have already been added to the scene, shouldn't they draw under the new color scheme?

    After this function runs, nothing changes on the display. It's still on the old color scheme.

    Any help would be much appreciated.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphicsPixmapItem to QPixmap to QImage and back again!

    After this function runs, nothing changes on the display.
    Does it change the image ? You can save it on disk and see the result.

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

    bruceariggs (10th September 2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem to QPixmap to QImage and back again!

    Yes, it does change the image. I used the save function to output the whole image before and after conversion and the images were different, yet the display never changed.

    HOWEVER, I did solve this issue while making optimizations.

    I was being silly and converting each tile piece to QImage and back, so I figured, "Why not just do the slow change once on the whole image", so I now do the color change on the entire image just once, instead of millions of times, and now for some reason the color change is showing up.

    So... Whatever. Maybe the original problem had something to do with a variable falling out of scope or what-not, but it doesn't matter now, the issue is resolved. =)

    Thank you for your help, though.
    Last edited by bruceariggs; 10th September 2011 at 14:09. Reason: I are grammar king!

Similar Threads

  1. Replies: 2
    Last Post: 15th March 2010, 10:03
  2. 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
  3. Replies: 2
    Last Post: 3rd November 2006, 22:20
  4. Replies: 7
    Last Post: 12th August 2006, 15:11
  5. QImage or QPixmap?
    By Dark_Tower in forum Qt Programming
    Replies: 9
    Last Post: 1st April 2006, 17:08

Tags for this Thread

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.