Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载位图时出现Android OutOfMemory错误_Android_Memory_Bitmap - Fatal编程技术网

加载位图时出现Android OutOfMemory错误

加载位图时出现Android OutOfMemory错误,android,memory,bitmap,Android,Memory,Bitmap,在应用程序中,我需要在创建时加载一些位图。 为了节省内存,我正在加载一幅图像,通过创建一个缩放的位图来重新缩放它,循环使用未缩放的位图,依此类推: bmpUnscaled = BitmapFactory.decodeResource(getResources(), R.drawable.cultivation_plant_resized_1); plant1 = Bitmap.createScaledBitmap(bmpUnscaled,(int) plant[0].getW

在应用程序中,我需要在创建时加载一些位图。 为了节省内存,我正在加载一幅图像,通过创建一个缩放的位图来重新缩放它,循环使用未缩放的位图,依此类推:

    bmpUnscaled = BitmapFactory.decodeResource(getResources(), R.drawable.cultivation_plant_resized_1);
      plant1 = Bitmap.createScaledBitmap(bmpUnscaled,(int) plant[0].getWidth(), (int) plant[0].getHeight(), true);
      bmpUnscaled.recycle();
    System.gc();
    bmpUnscaled = BitmapFactory.decodeResource(getResources(), R.drawable.cultivation_plant_resized_2);
      plant2 = Bitmap.createScaledBitmap(bmpUnscaled,(int) plant[0].getWidth(), (int) plant[0].getHeight(), true);
      bmpUnscaled.recycle();
    System.gc();
等等

我正在做这10幅图像,它们是相对于屏幕分辨率缩放的。 原始图像为PNG 570x900,最大660KB

有没有人有一些简单地节省内存的想法? 我现在很绝望…

你读过:

这篇文章包含有关使用位图的重要信息。

为什么说最大660kb?您不知道文件(例如PNG)和加载到内存中的位图之间的区别吗?该映像需要2.5MB堆空间才能加载570 x 900 x 4字节