码迷,mamicode.com
首页 > 其他好文 > 详细

little tips of painter.drawRect in Qt

时间:2016-09-29 18:11:37      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

一个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

标签:

原文地址:http://www.cnblogs.com/lt47/p/5920588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!