新しい画像を作成します。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.ラベル
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());
}
}