你的OPPA 2015-01-19 05:56
浏览 3710

QPixmap加载BMP图片,内存溢出,怎么办?

初始化后两个label可以显示图片,当点击按钮切换两个label显示图片后,求报错:QImage: out of memory, returning null image。我的每张图片都是6512*11635的BMP图片,大小为72.2M,我觉得是加载的缓存区不够大导致的,需要每次显示需要清理缓存区,不知道对不对,经过调试,问题就是在点击按钮后出发的函数里面的load加载图片。我用QPixmapCache::clear()也没有用,该肿么办?求大神指点
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;
}
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突