Results 1 to 2 of 2

Thread: Monochrome QImage transformation - void area looks black

  1. #1
    Join Date
    Nov 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Monochrome QImage transformation - void area looks black

    Hi there,

    I want to rotate a monochrome image of Type QImage using QImage::transformed method.
    After applying rotation, the background color of the void area is always black.

    The Image before Rotation lookes like this:
    original.gif

    After rotation, of 45° clockwise, it lookes like this:
    rotated.gif

    But it should look like this:
    rotated_correct.png

    My question is how can I make sure that the void area color is white?
    Thanks in advance!

    Here is my sample code:

    Qt Code:
    1. #include <QImage>
    2. #include <QPainter>
    3.  
    4. int main()
    5. {
    6. // size of square Image
    7. const int nSize = 100;
    8.  
    9. // create monochrome Image
    10. QImage img = QImage(nSize, nSize, QImage::QImage::Format_Mono);
    11.  
    12. QPainter pnt;
    13. pnt.begin(&img);
    14.  
    15. // fill background with white
    16. pnt.fillRect(0, 0, nSize, nSize, Qt::color0);
    17. pnt.setPen(QPen(Qt::color1));
    18. // draw a rectangle
    19. pnt.drawRect(0, 0, nSize-1, nSize-1);
    20. pnt.end();
    21.  
    22. img.save("original.bmp");
    23.  
    24. // rotate image
    25. m.rotate(45);
    26. img = img.transformed(m);
    27. img.save("rotated.bmp");
    28.  
    29. return 0;
    30. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Monochrome QImage transformation - void area looks black

    Please stop posting duplicate posts/threads.

    To your question:
    This is just a guess:
    Since this is a monochrome image, when you transform it, the areas out side the rect are not being painted on - which means they stay 0, which means black.
    Try using QImage::transformed().
    Last edited by high_flyer; 17th November 2017 at 12:12.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 4
    Last Post: 1st June 2016, 08:22
  2. QImage getting black areas for GIF frames
    By elephant in forum Qt Programming
    Replies: 4
    Last Post: 7th December 2013, 01:29
  3. Replies: 2
    Last Post: 10th June 2011, 15:16
  4. diffrence between void and virtual void
    By raphaelf in forum General Programming
    Replies: 2
    Last Post: 23rd February 2006, 14:58

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.