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

你的OPPA 你的OPPA 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
初始化后两个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;
}
}
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
你的OPPA
Qt 21,503 成员 26,693 内容