文章目录
1.copy
深度复制图像格式数据,可以指定区域。
QImage copy(const QRect &rect = QRect()) const;
inline QImage copy(int x, int y, int w, int h) const
{ return copy(QRect(x, y, w, h)); }
2.convertToFormat
格式转换,需要结合copy使用。单独使用,格式并未转换。
3.QPainter
新建图像格式,将源图像绘制过去,即可实现图像格式转换。
//图像格式转换
static void ImageFormatConvert(QImage& img, QImage::Format format) {
//相同则直接格式转换
if (img.format() == format)
{
return;
}
//新建图像
QImage imgRlt(img.width(), img.height(), format);
imgRlt.fill(QColor(255, 255, 255, 0));//默认底色
//图像转换
QPainter painter;
painter.begin(&imgRlt);
painter.drawImage(QPoint(0, 0), img);
painter.end();
//返回结果
img = imgRlt;
}
4.总结
QImage是Qt中复杂的图像处理对象,有利于生成指定图像结果。