QImage image(width, height, QImage::Format_Indexed8);
QVector<QRgb> grayTable; //设置颜色表
for (int i = 0; i < 256; i++)
grayTable.push_back(qRgb(i, i, i));
image.setColorTable(grayTable);
for (int i = 0; i < width; ++i)
{
for (int j = 0; j < height; ++j)
{
int color; //0-255
image.setPixel(i, j, color);
}
}
QString path; //路径+文件名
image.save(path);
【C++/Qt】QImage生成8位灰度图
最新推荐文章于 2023-06-29 11:27:16 发布