渲染 RGB 数据

TestRGB.h
#pragma once #include <QtWidgets/QWidget> #include "ui_TestRGB.h" class
TestRGB : public QWidget { Q_OBJECT public: TestRGB(QWidget *parent =
Q_NULLPTR); void paintEvent(QPaintEvent* event) override; // 绘制图形的函数 private:
Ui::TestRGBClass ui; };
TestRGB.cpp
#include "TestRGB.h" #include <QPainter> #include <QImage> static const int w
= 1080; static const int h = 720; TestRGB::TestRGB(QWidget *parent) :
QWidget(parent) { ui.setupUi(this); resize(w, h); } void
TestRGB::paintEvent(QPaintEvent* event) { QPainter painter(this); QImage
image(w, h, QImage::Format::Format_RGB888); // RGB888
每个像素点的每个颜色使用8位表示,一个像素点占用3个字节 unsigned char* data = image.bits(); // 图像所使用的内存
painter.begin(this); /* 改变每个像素点的颜色 */ for (int i = 0; i < h; i++) { int begin =
i * w * 3; // 每行的开始处 for (int j = 0; j < w * 3; j += 3) { data[begin + j] =
255; // R data[begin + j + 1] = 0; // G data[begin + j + 2] = 0; // B } }
painter.drawImage(0, 0, image); painter.end(); }
我们将 1024 * 720 的图像中的每个像素点渲染成红色。

程序运行结果如下所示:

 

技术
今日推荐
PPT
阅读数 135
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信