初始化后两个label可以显示图片,当点击按钮切换两个label显示图片后,求报错:QImage: out of memory, returning null image。我的每张图片都是6512*11635的BMP图片,大小为72.2M,我觉得是加载的缓存区不够大导致的,需要每次显示需要清理缓存区,不知道对不对,求大神指点下
void MinImage::loadMinImage() //初始化
{
i = 1;
QDir dir("/image1","*.bmp");
if(!dir.exists())
return;
dir.setSorting(QDir::Time);//文件排列方式:时间
background1.load(QString("E:/image1/%1").arg(dir[dir.count()-i]));
background1 = background1.scaled(background1.width(),background1.height(),Qt::KeepAspectRatio);
label_image1->setPixmap(background1);
i++;
background2.load(QString("E:/image1/%1").arg(dir[dir.count()-i]));
background2 = background2.scaled(background2.width(),background2.height(),Qt::KeepAspectRatio);
label_image2->setPixmap(background2);
}
void MinImage::Right_Button_clicked()
{
QDir dir("/image1","*.bmp");
dir.setSorting(QDir::Time);
if(i==dir.count())
{
QMessageBox::warning(this,"warning","Has reached the final!");
}
else
{
i++;
background1.load(QString("E:/image1/%1").arg(dir[dir.count()-i+1]));
background1 = background1.scaled(background1.width(),background1.height(),Qt::KeepAspectRatio);
label_image1->setPixmap(background1);
background2.load(QString("E:/image1/%1").arg(dir[dir.count()-i]));
background2 = background2.scaled(background2.width(),background2.height(),Qt::KeepAspectRatio);
label_image2->setPixmap(background2);
}
}
void MinImage::Left_Button_clicked()
{
QDir dir("/image1","*.bmp");
dir.setSorting(QDir::Time);
if(i==2)
{
QMessageBox::warning(this,"warning","Has reached the final!");
}
else
{
i--;
background1.load(QString("E:/image1/%1").arg(dir[dir.count()-i+1]));
background1 = background1.scaled(background1.width(),background1.height(),Qt::KeepAspectRatio);
label_image1->setPixmap(background1);
background2.load(QString("E:/image1/%1").arg(dir[dir.count()-i]));
background2 = background2.scaled(background2.width(),background2.height(),Qt::KeepAspectRatio);
label_image2->setPixmap(background2);
qDebug()<<i;
}
}
------解决思路----------------------
你前面的用的QPixmap加载文件的代码,内部也是通过QImageReader 读入到QImage,而后转成 QPixmap 来实现的。
不然,你不觉得,你没有用QImage,但是报错的却是QImage,很奇怪么?