QT QImage

1. 新建图片

//新建图片
QImage image(100,200,QImage::Format_RGB32);

//从本地路径中新建方法1
QImage image(filename);

//从本地路径中新建方法2
QImage* img=new QImage;
if(! ( img->load(filename) ) ) //加载图像
{
    QMessageBox::information(this,
                 tr("打开图像失败"),
                 tr("打开图像失败!"));
    delete img;
    return;
}

2. Label中添加图像

ui->ImageLabel->setPixmap(QPixmap::fromImage(image));
ui->ImageLabel->setScaledContents(true);//设置图像填满Label

3. 设置图像的背景颜色

//设置图片的背景颜色
QColor destcolor(255,255,255);
//方法1
image.fill(destcolor.rgba());
//方法2
for(int h=0; h<image.height(); h++)
{
    for(int w=0; w<image.width(); w++)
    {
        image.setPixel(w,h,destcolor.rgba());
    }
}
发布了110 篇原创文章 · 获赞 2 · 访问量 3751

猜你喜欢

转载自blog.csdn.net/qq_40041064/article/details/103397928
今日推荐