Results 1 to 4 of 4

Thread: QPainter and QImage

  1. #1
    Join Date
    Aug 2006
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainter and QImage

    Hi, I'm trying to save somthing I draw using QPainter to image file. My code looks like that:

    QImage image(800,600,QImage::Format_RGB32);
    QPainter paint;
    paint.begin(&image);
    paint.drawRect(10,10,50,50);
    paint.end();
    image.save("image.bmp");

    What I get is a totally black image with some different colours strips. But when I use existing image like that:

    QImage image("image.bmp");
    QPainter paint;
    paint.begin(&image);
    paint.drawRect(10,10,50,50);
    paint.end();
    image.save("image.bmp");

    ewerything is fine. I don't know where is the problem. Maybe you will have some ideas. Thanks in avance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPainter and QImage

    The first image will be constructed as black (default) and you are drawing a rect with black pen&brush (default).
    J-P Nurmi

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

    Default Re: QPainter and QImage

    In other words try adding image.fill(Qt::white) after you construct the object.

  4. #4
    Join Date
    Aug 2006
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter and QImage

    Big thanks for fast reply. I haven't noticed that, now it is working correct. Tell me if it's posible to construct image as white?

Similar Threads

  1. Diff between QImage, QPixmap, QPicture
    By nupul in forum Newbie
    Replies: 6
    Last Post: 30th April 2008, 02:02
  2. gdi and QPainter
    By Elder Orb in forum Qt Programming
    Replies: 13
    Last Post: 29th September 2006, 12:43
  3. QImage or QPixmap?
    By Dark_Tower in forum Qt Programming
    Replies: 9
    Last Post: 1st April 2006, 17:08
  4. Trouble with image painting (QPainter + QImage)
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 20:25

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.