0
View를 확장하는 여러 개의 사용자 정의보기가 포함 된 앱이 있습니다. 각 사용자 정의보기는 일련의 이미지 (~ 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