1.void setDotsPerMeterX(int);

设置每米有多少个像素

/*!Sets the number of pixels that fit horizontally in a physicalmeter, to \a x.Together with dotsPerMeterY(), this number defines the intendedscale and aspect ratio of the image, and determines the scaleat which QPainter will draw graphics on the image. It does notchange the scale or aspect ratio of the image when it is renderedon other paint devices.\sa dotsPerMeterX(), {QImage#Image Information}{Image Information}
*/
void QImage::setDotsPerMeterX(int x)
{if (!d || !x)return;detach();if (d)d->dpmx = x;
}

2.void setDotsPerMeterY(int);

/*!Sets the number of pixels that fit vertically in a physical meter,to \a y.Together with dotsPerMeterX(), this number defines the intendedscale and aspect ratio of the image, and determines the scaleat which QPainter will draw graphics on the image. It does notchange the scale or aspect ratio of the image when it is renderedon other paint devices.\sa dotsPerMeterY(), {QImage#Image Information}{Image Information}
*/
void QImage::setDotsPerMeterY(int y)
{if (!d || !y)return;detach();if (d)d->dpmy = y;
}

3.void fill(const QColor &color);

/*!\fn void QImage::fill(const QColor &color)\overloadFills the entire image with the given \a color.If the depth of the image is 1, the image will be filled with 1 if\a color equals Qt::color1; it will otherwise be filled with 0.If the depth of the image is 8, the image will be filled with theindex corresponding the \a color in the color table if present; itwill otherwise be filled with 0.\since 4.8
*/
void QImage::fill(const QColor &color)
{if (!d)return;detach();// In case we run out of memoryif (!d)return;QRgba64 opaque = color.rgba64();opaque.setAlpha(65535);switch (d->format) {case QImage::Format_RGB32:case QImage::Format_ARGB32:fill(color.rgba());break;case QImage::Format_ARGB32_Premultiplied:fill(qPremultiply(color.rgba()));break;case QImage::Format_RGBX8888:fill(ARGB2RGBA(color.rgba() | 0xff000000));break;case QImage::Format_RGBA8888:fill(ARGB2RGBA(color.rgba()));break;case QImage::Format_RGBA8888_Premultiplied:fill(ARGB2RGBA(qPremultiply(color.rgba())));break;case QImage::Format_BGR30:fill(qConvertRgb64ToRgb30<PixelOrderBGR>(opaque));break;case QImage::Format_RGB30:fill(qConvertRgb64ToRgb30<PixelOrderRGB>(opaque));break;case QImage::Format_RGB16:fill((uint) qConvertRgb32To16(color.rgba()));break;case QImage::Format_Indexed8: {uint pixel = 0;for (int i=0; i<d->colortable.size(); ++i) {if (color.rgba() == d->colortable.at(i)) {pixel = i;break;}}fill(pixel);break;}case QImage::Format_Mono:case QImage::Format_MonoLSB:if (color == Qt::color1)fill((uint) 1);elsefill((uint) 0);break;case QImage::Format_RGBX64:qt_rectfill<quint64>(reinterpret_cast<quint64*>(d->data), opaque,0, 0, d->width, d->height, d->bytes_per_line);break;case QImage::Format_RGBA64:qt_rectfill<quint64>(reinterpret_cast<quint64*>(d->data), color.rgba64(),0, 0, d->width, d->height, d->bytes_per_line);break;case QImage::Format_RGBA64_Premultiplied:qt_rectfill<quint64>(reinterpret_cast<quint64 *>(d->data), color.rgba64().premultiplied(),0, 0, d->width, d->height, d->bytes_per_line);break;default: {QPainter p(this);p.setCompositionMode(QPainter::CompositionMode_Source);p.fillRect(rect(), color);}}
}/*!\fn void QImage::fill(uint pixelValue)Fills the entire image with the given \a pixelValue.If the depth of this image is 1, only the lowest bit is used. Ifyou say fill(0), fill(2), etc., the image is filled with 0s. Ifyou say fill(1), fill(3), etc., the image is filled with 1s. Ifthe depth is 8, the lowest 8 bits are used and if the depth is 16the lowest 16 bits are used.If the image depth is higher than 32bit the result is undefined.\note There are no corresponding value getter, though QImage::pixelIndex()will return the same value for indexed formats, and QImage::pixel() forRGB32, ARGB32, and ARGB32PM formats.\sa depth(), {QImage#Image Transformations}{Image Transformations}
*/
void QImage::fill(uint pixel)
{if (!d)return;detach();// In case detach() ran out of memoryif (!d)return;if (d->depth == 1 || d->depth == 8) {int w = d->width;if (d->depth == 1) {if (pixel & 1)pixel = 0xffffffff;elsepixel = 0;w = (w + 7) / 8;} else {pixel &= 0xff;}qt_rectfill<quint8>(d->data, pixel, 0, 0,w, d->height, d->bytes_per_line);return;} else if (d->depth == 16) {if (d->format == Format_RGB444)pixel |= 0xf000;qt_rectfill<quint16>(reinterpret_cast<quint16*>(d->data), pixel,0, 0, d->width, d->height, d->bytes_per_line);return;} else if (d->depth == 24) {if (d->format == Format_RGB666)pixel |= 0xfc0000;qt_rectfill<quint24>(reinterpret_cast<quint24*>(d->data), pixel,0, 0, d->width, d->height, d->bytes_per_line);return;} else if (d->depth == 64) {qt_rectfill<quint64>(reinterpret_cast<quint64*>(d->data), QRgba64::fromArgb32(pixel),0, 0, d->width, d->height, d->bytes_per_line);return;}if (d->format == Format_RGB32)pixel |= 0xff000000;if (d->format == Format_RGBX8888)
#if Q_BYTE_ORDER == Q_LITTLE_ENDIANpixel |= 0xff000000;
#elsepixel |= 0x000000ff;
#endifif (d->format == Format_BGR30 || d->format == Format_RGB30)pixel |= 0xc0000000;qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel,0, 0, d->width, d->height, d->bytes_per_line);
}template <class T> static
inline void qt_rectfill(T *dest, T value,int x, int y, int width, int height, qsizetype stride)
{char *d = reinterpret_cast<char*>(dest + x) + y * stride;if (uint(stride) == (width * sizeof(T))) {qt_memfill(reinterpret_cast<T*>(d), value, qsizetype(width) * height);} else {for (int j = 0; j < height; ++j) {dest = reinterpret_cast<T*>(d);qt_memfill(dest, value, width);d += stride;}}
}template<> inline void qt_memfill(quint8 *dest, quint8 color, qsizetype count)
{memset(dest, color, count);
}

先把QColor转成整数,然后调用fill(uint pixel)填充。

Qt源码分析--QImage(8)相关推荐

  1. Qt源码分析--QImage(1)

    QImage 类提供独立于硬件的图像表示 (允许直接访问像素数据,且可以用作描绘设备). QImage 是为 I/O 和直接像素访问和操作而设计和优化的. 因为 QImage 是 QPaintDevi ...

  2. Qt源码分析之QObject

    Qt的QObject 1.试验代码: #include <QApplication> #include <QtCore> #include <QtGui> int ...

  3. Qt源码分析之信号和槽机制

    Qt的信号和槽机制是Qt的一大特点,实际上这是和MFC中的消息映射机制相似的东西,要完成的事情也差不多,就是发送一个消息然后让其它窗口响应,当然,这里的消息是广义的 说法,简单点说就是如何在一个类的一 ...

  4. Qt源码分析--QSettings

    定义: QSettings 类提供与平台无关的持久应用程序设置. 官方例子: QSettings settings("MySoft", "Star Runner" ...

  5. 【Qt】Log4Qt(三)源码分析

    Log4Qt(三)源码分析 1.分层架构 1.1 核心对象 1.2 支持对象 2.源码分析 2.1 宏 2.1.1 LOG4QT_DECLARE_QCLASS_LOGGER 2.1.2 LOG4QT_ ...

  6. Qt 事件机制源码分析 QApplication exec 源码分析 多图超级详细

    前言: 不熟悉qt 源码结构的 可以先看这一篇 点我点我点我 写qt 的都知道 以下代码, 这段代码究竟的运行机制是怎么样的 咱们一步一步的看 QApplication a(argc, argv);Q ...

  7. Solr初始化源码分析-Solr初始化与启动

    用solr做项目已经有一年有余,但都是使用层面,只是利用solr现有机制,修改参数,然后监控调优,从没有对solr进行源码级别的研究.但是,最近手头的一个项目,让我感觉必须把solrn内部原理和扩展机 ...

  8. 14.QueuedConnection和BlockingQueuedConnection连接方式源码分析

    QT信号槽直连时的时序和信号槽的连接方式已经在前面的文章中分析过了,见https://blog.csdn.net/Master_Cui/article/details/109011425和https: ...

  9. sigslot库源码分析

    言归正传,sigslot是一个用标准C++语法实现的信号与槽机制的函数库,类型和线程安全.提到信号与槽机制,恐怕最容易想到的就是大名鼎鼎的Qt所支持的对象之间通信的模式吧.不过这里的信号与槽虽然在概念 ...

最新文章

  1. MySQL中锁详解(行锁、表锁、页锁、悲观锁、乐观锁等)
  2. 2015.11.10 asn1学习笔记
  3. python元组的定义方式_序列之元组详解
  4. oracle preparedstatement,【JDBC】java PreparedStatement操作oracle数据库
  5. Winfrom实用代码项目
  6. Oracle数据库比较日期时间的大小
  7. java工程师_Java开发工程师需要掌握哪些技能?
  8. js中apply和join
  9. Dijkstra-解决最短路径问题
  10. 计算机科学与因果关系,计算机科学与技术
  11. 宏基4752g linux驱动下载,宏碁笔记本及应用程序驱动下载_硬件驱动下载
  12. 深度学习:YOLO算法与其优化
  13. matlab中有非线性模型吗,仿真非线性模型Matlab
  14. SDRAM控制器——添加读写FIFO
  15. ios 版手机迅雷的安装方法
  16. ArduinoUNO实战-第十七章-火焰传感器
  17. Modular Arithmetic
  18. 你应该学点哲学的20个理由:不为拥有深奥的思想,只为更好地生活
  19. sqlserver:关于timestamp时间戳 rowversion
  20. 关于JavaScript中的date和java中的date差14小时问题

热门文章

  1. 神威OpenFOAM——最流行的开源CFD软件与神威·太湖之光的珠联璧合
  2. 陈欧体程序员版And各种版本
  3. 如何查看网页操作中调用的js方法
  4. linux操作系统认手机,Linux移动操作系统postmarketOS已适配200款移动设备 包括手机和平板电脑...
  5. 谷歌小恐龙游戏源代码(1)
  6. 从反向输出一个四位数由难到易引申到反向输出一个n位数
  7. 【愚公系列】2023年04月 攻防世界-MOBILE(Android2.0)
  8. 万事无忧之SEO GOOGLE优化秘诀
  9. 牛客网Chino with Equation【组合数】
  10. 轻流入选 Forrester 中国制造商通过低代码加速价值交付案例研究报告