QT QImage

1. Create a new picture

//新建图片
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 to add image

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

3. Set the background color of the image

//设置图片的背景颜色
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());
    }
}

 

Published 110 original articles · won praise 2 · Views 3751

Guess you like

Origin blog.csdn.net/qq_40041064/article/details/103397928