0
我有一個應用程序,其中包含幾個擴展視圖的自定義視圖。每個自定義視圖加載一堆圖像(〜20)並縮小它們:Android,圖像加載和內存分配
mBmp[img1] = BitmapFactory.decodeStream(context.getAssets().open("img01.png"));
mBmp[img2] = BitmapFactory.decodeStream(context.getAssets().open("img02.png"));
mBmp[img3] = BitmapFactory.decodeStream(context.getAssets().open("img03.png"));
...
mBmp[img20] = BitmapFactory.decodeStream(context.getAssets().open("img20.png"));
這些都在try - catch塊中。
這部分不會引起任何問題。但是,一旦我達到縮放圖像的點,我稱之爲它採用createScaledBitmap我的尺度方法:
protected void scaleImages(float mWidth, float mHeight)
{
float mXRat = mWidth/1024;
float mYRat = mHeight/600;
for (int i = 0; i < mBmp.length; i++)
{
float oldX = mBmp[i].getWidth();
float oldY = mBmp[i].getHeight();
double newX = (mXRat * oldX);
double newY = (mYRat * oldY);
Bitmap newBmp = Bitmap.createScaledBitmap(mBmp[i], (int) newX, (int) newY, true);
mBmp[i] = newBmp;
}
}
我得到我試圖分配太多的內存錯誤。
01-25 10:16:44.227: ERROR/dalvikvm-heap(14548): 1497600-byte external allocation too large for this process.
01-25 10:16:44.227: ERROR/dalvikvm(14548): Out of memory: Heap Size=4871KB, Allocated=2544KB, Bitmap Size=18683KB
01-25 10:16:44.227: ERROR/GraphicsJNI(14548): VM won't let us allocate 1497600 bytes
當擴展到RAM礦井沒有單一的形象應該採取這樣的記憶,那麼爲什麼正試圖調整它們的大小,當它跑了呢?
您是否在意提供可能的解決方案? – Hamid 2011-01-25 11:16:17