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);
}
相关推荐
xcyxiner19 小时前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner1 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner2 天前
DicomViewer (添加模型类)3
qt
xcyxiner3 天前
DicomViewer (目录调整) 2
qt
xcyxiner3 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR0064 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术4 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园4 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob4 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享5 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm