如何解决解码多张图片时出现的内存不足情况

kg200704 2008-04-14 05:13:54
我通过解码类实现对多张jpeg格式的图片进行解码,接完以后将图片指针保存到图片数组中。但是当调用特定函数对图片进行处理时弹出内存不足的警告,请问如何处理啊。
我试过在.mmp文件中通过
EPOCHEAPSIZE 0x5000 0x400000
命令增加heap的大小,但是不管用。
希望各位给予解答,谢谢。
...全文
390 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
kg200704 2008-04-21
  • 打赏
  • 举报
回复
谢谢楼上指点,还有问题问大家。我想获取某张图片某个点的像素的RGB颜色值。
我使用以下两种方法

CFbsBitmap* MyBitmap;

TUint32 getPixel;
TRgb MyRgb;

TBitmapUtil bitmapUtil(MyBitmap);

1.
MyBitmap->GetPixel(MyRgb, TPoint(xPos, yPos));

2.
getPixel = bitmapUtil.GetPixel();
MyRgb = TRgb(getPixel);

二者有什么本质区别吗?为什么都习惯用后者?谢谢解答!!!
whhema 2008-04-21
  • 打赏
  • 举报
回复
系统解码的类确实很占内存空间。
你可以解码之后拉伸到一个比较小的size,然后保存CFbsBitmap即可。系统解码的类动态创建
lspo816 2008-04-20
  • 打赏
  • 举报
回复
内存泄漏的问题通过HookLogger来找吧,很快就能找到
kg200704 2008-04-17
  • 打赏
  • 举报
回复
谢谢lsp0816的指点,也感谢楼下上朋友们的建议。
lspo816 2008-04-15
  • 打赏
  • 举报
回复
iImageArray.Append(new(ELeave)CFbsBitmap);
iImageArray[aIndex]-> Duplicate(aDecoratedBitmap-> Handle());
我感觉这样写比较好
CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
bmp->Duplicate(aDecoratedBitmap-> Handle());
iImageArray.Append(bmp);


你每次插入的都是指定aIndex,但aIndex并不一定总是指向数组的最后一条数据
Insert和Append方式都可以插入数据
Append总是插入在最后一条,Insert则可以插入任何位置
iImageArray.Insert(aDecoratedBitmap, aIndex); 如果这么做aDecoratedBitmap实际上交给iImageArray了,你释放内存的时候就要小心了,不要重复释放
kg200704 2008-04-15
  • 打赏
  • 举报
回复
谢谢您的解答,还有个问题需要问您。以下代码
iImageArray.Append(new(ELeave)CFbsBitmap);
iImageArray[aIndex]-> Duplicate(aDecoratedBitmap-> Handle());

iImageArray.Insert(aDecoratedBitmap, aIndex);
有什么本质区别,不都是将图片指针添加到RPointerArray数组里吗。
谢谢
lspo816 2008-04-15
  • 打赏
  • 举报
回复
你设置最大堆为400k,你单张图片最少50k,那最多8张内存就不够用了
你应该修改程序的策略,尽量减少在内存中图片的张数,即显示的才放在内存中,加上预解码处理。或者再增大堆栈的大小
kg200704 2008-04-15
  • 打赏
  • 举报
回复
贴几个关键函数,大家帮忙看看,有什么地方不妥的

图片大约50-100kb
1.图片解码函数:
void CImageOperateDecoder::DecodeDecoratedImageL(TInt aIndex, const TDesC& aImagePath)
{
delete iDir;
iDir = NULL;

User::LeaveIfError(iFs.GetDir(aImagePath, KEntryAttNormal,
ESortByDate, iDir));

TBuf<32> picturepath(aImagePath);
picturepath.Append((*iDir)[aIndex].iName);

delete iDecoder;
iDecoder = NULL;

//iDecoder FileNewL
iDecoder = CImageDecoder::FileNewL(iFs, picturepath);

TFrameInfo frmInfo = iDecoder->FrameInfo(0);

TRect rectOfImage = frmInfo.iFrameCoordsInPixels;
TSize srcSize = aSrcBitmap->SizeInPixels();

delete iDecoratedImage;
iDecoratedImage = NULL;

iDecoratedImage = new(ELeave)CFbsBitmap();
//iImage create 24 bpp
iDecoratedImage->Create(rectOfImage.Size(), EColor16M);
//convert
iDecoder->Convert(&iStatus, *iDecoratedImage, 0);

SetActive();
}

2.解码多张图片的RunL实现
void CImageOperateDecoder::RunL()
{
//将图片保存到RPointerArray数组中
iModel.SetDecoratedImage(iDecoratedImage, iIndex);
iIndex++;
//GetCountL()为文件夹中图片的个数
if(iIndex < GetCountL())
{
DecodeDecoratedImageL(iIndex, KMaterialPath);
}

}

3.保存图片到RPointerArray数组中
void CImageOperateModel::SetDecoratedImage(CFbsBitmap* aDecoratedBitmap, TInt aIndex)
{
iImageArray.Append(new(ELeave)CFbsBitmap);
iImageArray[aIndex]->Duplicate(aDecoratedBitmap->Handle());
}

谢谢各位!
Juncof 2008-04-15
  • 打赏
  • 举报
回复
EPOCHEAPSIZE 0x5000 0x400000 是20KB~4MB吧
写个循环,一个个的删(记得删除后一定要设置指针为空),C类的析构函数里面删除才比较好用
kg200704 2008-04-15
  • 打赏
  • 举报
回复
我试过了,还是不行。
换成Close()也不行。
lspo816 2008-04-15
  • 打赏
  • 举报
回复
RPointerArray析构的时候需要调ResetAndDestroy
kg200704 2008-04-15
  • 打赏
  • 举报
回复
谢谢,我用以上两种方法的时候退出时都出现内存泄漏,我在析构函数中已经做了相应的处理了。但是还有问题,就是RPinterArray数组这里的,如果不使用RPinterArray,一切正常。
lspo816 2008-04-14
  • 打赏
  • 举报
回复
图片多大一张,建议贴写代码,让大家看看哪些地方可以优化
如果多张图片解码同时储存在内存中,很耗资源的,可以考虑用到的时候才解码,用完释放

3,120

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧