Results 1 to 9 of 9

Thread: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

  1. #1
    Join Date
    Apr 2009
    Location
    the Netherlands
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    I am having problems rendering a scene for the second time. The first time I do a QGraphicsScene->render(...) it renders ok and I am able to save the QImage as a png file. However when I try the same again on the same scene but a different portion(using a new QPainter and a new QImage) I get partly garbled rendering. (a lot of horizontal stripes through the picture)

    This is the piece of test code that does the rendering and creates an image. The second image created contains the garbled picture. (Also when I call this routine again both images get garbled)

    Qt Code:
    1. QImage *img;
    2. QPainter *paint;
    3.  
    4. img = new QImage(QSize(960, 600), QImage::Format_ARGB32);
    5. paint = new QPainter(img);
    6. itsGraphicResourceScene->render(paint, QRectF(), QRectF(3070, 0, 960, 600));
    7. paint->end();
    8. img->save("test1.png", "png");
    9. delete img;
    10. delete paint;
    11.  
    12. img = new QImage(QSize(960, 600), QImage::Format_ARGB32);
    13. paint = new QPainter(img);
    14. itsGraphicResourceScene->render(paint, QRectF(), QRectF(3910, 0, 960, 600));
    15. paint->end();
    16. img->save("test2.png", "png");
    17. delete img;
    18. delete paint;
    To copy to clipboard, switch view to plain text mode 

    I have even tried to completely refresh the scene by using QGrahicsScene->clear() and then adding all graphic items again. With the same results. Also, I have tried creating a new scene and added the graphic items to it and rendered from that scene (with the same results...)

    Unfortunately I am not able to add a screenshot because the forum only accepts an URL when inserting a image

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    Quote Originally Posted by alwin View Post
    Unfortunately I am not able to add a screenshot because the forum only accepts an URL when inserting a image
    You can add an attachment containing the image. Also please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    Since the only difference I see in the second part of your code is the rect provided in render(), did you try to call it with same coordinates?

    Then we will know if the problem is related to coordinates of if there is a mistake elsewhere.

  4. #4
    Join Date
    Apr 2009
    Location
    the Netherlands
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    Thanks both for your suggestions. I will try to use the same coordinates first, although I don't think that will help, because when I call this routine again it also garbles up the first image which in the first run is ok. I will try anyway and post results. After that I will try to reproduce the problem using minimal code. Maybe then I will even find the problem.

    I am using my own class GraphicTask which is derived from QGraphicsItem.
    In that class I override boundingRect(), paint(), mousePressEvent(), and mouseReleaseEvent(). Could that have anything to do with it? I will post the minimal example ASAP.

    I attached the two images test1.png and test2.png. test1.png is ok (first run) and test2.png is garbled as you will notice. I also noticed that the second image always has about three times the byte size as the first. This could be an important clue, because the images are not that different.
    The attached images are not the original images, I had to flatten them in the GIMP because the where transparant and in their original form not displayed correctly after uploading. (side question: How do I loose the transparancy in QT? I don't need nor want it)

    Thanks both for your suggestions so far.
    Attached Images Attached Images

  5. #5
    Join Date
    Apr 2009
    Location
    the Netherlands
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    I created another image, because I suspected it had something to do with the graphicTask objects (the green and blue rectangles). Some of these objects are partly in the rendered picture and partly outside it. (i.e. boundingRect() is partly outside the image) I shifted these task objects and recreated the image. Now I see that some of the timeline of the first render is also in the second image. This is strange because I use a newly created image (see the code) and render to that.
    I also created an image without any task obejcts (only the timeline and the night-time rectangles (the grey rectangles) are in the image. When I do this it does not garble up the second image (see attached test2.jpg)
    Attached Images Attached Images

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    So how about that example code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    Make sure to initialize the image. By default it's full of uninitialized pixels, and QGraphicsScene::render() will blend on top (source-over composition). When your app starts, chances are when you create the first image, it's going to be blank because the OS blanks those bits. Second time however, the image is likely to contain junk from the last time you rendered.

    See QImage::fill(). Don't know if that will solve the problem but it's worth a shot...
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  8. #8
    Join Date
    Apr 2009
    Location
    the Netherlands
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    After two days, I found the problem! It wasn't in the software (at least not in my software). I remembered seeing such garbled stripes once more in another application under Linux. The laptop I use is quite new and uncommon that its display driver for linux is probably not widely tested. However I suspected that the driver was the problem and compiled the software under windows. And surely the problem was gone! It seems the display driver for my DELL Latitude E6400 is the problem.
    Anyway, thanks folks for your replies!

  9. #9
    Join Date
    Nov 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem rendering garbled when rendering twice (QGraphicsScene->render(..))

    Quote Originally Posted by Bitto View Post
    Make sure to initialize the image. By default it's full of uninitialized pixels, and QGraphicsScene::render() will blend on top (source-over composition). When your app starts, chances are when you create the first image, it's going to be blank because the OS blanks those bits. Second time however, the image is likely to contain junk from the last time you rendered.

    See QImage::fill(). Don't know if that will solve the problem but it's worth a shot...
    This explanation is the right point and helps me out of my struggle. Thanks Bitto.

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.