Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImage weird artifacts when drawing with QPainter
Forum Updated to NodeBB v4.3 + New Features

QImage weird artifacts when drawing with QPainter

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 450 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Infestor
    wrote on last edited by
    #1

    Hi,

    Im new to Qt and am currently experimenting with QPainter/Image. Consider the following code:

     QImage blankmap; //white image of size 1470*850
        blankmap.load("images/maps/blankmap.png");
    
    
        QImage gray; // gray 10*10 image
        gray.load("gray.png");
    
        QPainter painter;
    
        painter.begin(&blankmap);
        QRect r(0, 0, 10, 10);
        for (int i = 0; i < 1470; i += 10) {
            for (int j = 0; j < 850; j += 10) {
                r.setX(i);
                r.setY(j);
                painter.drawImage(r, gray);
            }
        }
        painter.end();
        blankmap.save("map1.png");
    

    My expectation now would be that the resulting image is just gray. However as you can see it has two white stripes. Can someone explain this to me?
    alt text

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Your rectangle is wrong. See QRect::setX() and QRect::setY().

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Infestor
        wrote on last edited by
        #3

        Is there a functoin that does what i want it to do? At first glance it seems like there is not. Translate() looks like it would work though.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Infestor said in QImage weird artifacts when drawing with QPainter:

          Is there a functoin that does what i want it to do? At first glance it seems like there is not.

          Then you should take a second look. You want to move your rectangle.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved