yanqy

导航

 

源码:

#include <QImage>

#include <QPainter>

void drawLines(QImage& image) {
QPainter painter(&image);

QPen pen(Qt::black);
pen.setWidth(2);   // 设置线宽2 dot
painter.setPen(pen);

// 绘制水平线,分8份
for (int y = 89; y < image.height()-10; y += 90) {
painter.fillRect(0, y, image.width(), 2, Qt::black);
}

// 绘制垂直线,分8份
for (int x = 159; x < image.width()-10; x += 160) {
painter.fillRect(x, 0, 2, image.height(), Qt::black);
}

// 绘制对角线连接线 2 dot
painter.drawLine(0, 0, image.width() - 1, image.height() - 1);
painter.drawLine(image.width() - 1, 0, 0, image.height() - 1);
}

int getPng_GridLine() {
// 创建空白的 RGBA 图像
QImage image(1280, 720, QImage::Format_RGBA8888);
image.fill(Qt::transparent);   // 设置整个image透过
// image.fill(Qt::white);          // 设置整个image白色
// 绘制线条
drawLines(image);

// 保存图像
image.save("lines111.png");

return 0;
}

posted on 2024-04-23 13:51  yanqy  阅读(283)  评论(0)    收藏  举报