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

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥15 MCNP里如何定义多个源?
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services