Qt QImage和QPixmap使用与区别
重点:
1.QPixmap主要用于在界面上显示图像,它可以对图像进行缩放,可以加载BMP、JPG、PNG等格式的图片文件,然后在 OLabel组件上显示图像。
2.QImage可以读取BMP、JPG、PNG 等格式的图片件,存储图像中所有像素的颜色数据。QImage的接口函数可以实现图像的缩放、旋转、镜翻转等简单处理,可以转换颜色数据格式。因为QImage可以读写图像中每个像素的颜色数掘所以结合图像处理算法,我们可以对图像进行各种处理,例如调整亮度、调整对比度、模糊处理等。
QImage转换数据并采用QPixmap显示
void MainWindow::on_btnFormatConvert_clicked(QString fileName)
{//图像格式转换
QImage m_image;
m_image.load(fileName); //从当前文件重新载入
int index=ui->comboFormat->currentIndex();
if (index ==0)
m_image.convertTo(QImage::Format_RGB16); //RGB565
else if (index ==1)
m_image.convertTo(QImage::Format_RGB888); //RGB888
else if (index ==2)
m_image.convertTo(QImage::Format_RGB32); //RGBx888
else if (index ==3)
// newImage = image.convertToFormat(QImage::Format_Grayscale8); //不改变原图
// newImage = image.convertedTo(QImage::Format_Grayscale8); //不改变原图像
m_image.convertTo(QImage::Format_Grayscale8); //8位灰度
else if (index ==4)
m_image.convertTo(QImage::Format_Grayscale16);//16位灰度
else if (index ==5)
m_image.convertTo(QImage::Format_Indexed8); //8位索引
else
return;
QPixmap pixmap=QPixmap::fromImage(m_image); //刷新界面的图像显示
ui->labPic->setPixmap(pixmap);
}两者相互转换
QImage image = pixmap.toImage(); QPixmap pixmap = QPixmap::fromImage(image);
到此这篇关于Qt QImage和QPixmap使用与区别的文章就介绍到这了,更多相关Qt QImage QPixmap内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
详解Visual Studio 2019(VS2019) 基本操作
这篇文章主要介绍了详解Visual Studio 2019(VS2019) 基本操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-03-03


最新评论