little tips of painter.drawRect in Qt

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了little tips of painter.drawRect in Qt相关的知识,希望对你有一定的参考价值。

一个QImage或QPixmap新建变量时,第一次填充图片时设置的宽高正常(fill),其后的绘制操作(draw)则会在绘制的矩形底边和右边加上painter.pen().width()

在下面代码17行设置端点查看内存可以直观看到只在右边和底边++

 1 // 1.  生成掩码图
 2     const int width = 32;
 3     const int height = 20;
 4     QImage maskImg(width, height, QImage::Format_Mono);
 5     QPainter maskPainter(&maskImg);
 6     //
 7     maskPainter.setPen(QPen(Qt::white, 0));
 8     maskPainter.setBrush(Qt::white);
 9     maskPainter.drawRect(0, 0, width, height);
10     maskPainter.setPen(QPen(Qt::black, 0));
11     maskPainter.setBrush(Qt::black);
12     maskPainter.drawRect(16, -16, width, height);
13     maskPainter.setPen(QPen(Qt::black, 0));
14     maskPainter.setBrush(Qt::black);
15     maskPainter.drawRect(16, 16, 2, 3);
16 
17     maskImg.save("/home/lt47/Desktop/ORIGIN.jpg");
18     qDebug() << maskImg.byteCount();
19     qDebug() << maskImg.bytesPerLine();
20     QRgb b = maskImg.pixel(16,20);
21     qDebug() << qRed(b) << qGreen(b) << qBlue(b);
22     QRgb ww = maskImg.pixel(15,20);
23     qDebug() << qRed(ww) << qGreen(ww) << qBlue(ww);

 

以上是关于little tips of painter.drawRect in Qt的主要内容,如果未能解决你的问题,请参考以下文章

SGU104 Little shop of flowers (DP)

POJ 题目1157 LITTLE SHOP OF FLOWERS(DP)

POJ 1157 - LITTLE SHOP OF FLOWERS

SGU 104 Little Shop of Flowers (DP&打印路径)

[2016-06-21]OMG美语笔记-Do you like a lot of sugar in your coffee of just a little pinch?

CF453D Little Pony and Elements of Harmony