gpt4 book ai didi

java - 加载图像时出现内存不足错误

转载 作者:搜寻专家 更新时间:2023-11-01 09:08:01 26 4
gpt4 key购买 nike

我想在android上加载图片

background = BitmapFactory.decodeResource(getResources(),R.drawable.hangmanbegin);    
background = Bitmap.createScaledBitmap(background,screenx,screeny,false);

图像是 800*1280 像素,所以如果我是正确的,它应该使用大约 3MB 的内存空间?但是我的堆就在那个阶段从 15MB 增长到 29MB,所以没有窗口或上下文泄漏?

这怎么解释? zh 你能做些什么呢?

提前致谢!

最佳答案

Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the camera on the Galaxy Nexus takes photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is ARGB_8888 (the default from the Android 2.3 onward) then loading this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the per-app limit on some devices.

来自 http://developer.android.com/training/displaying-bitmaps/index.html

信用及其下方一种接近修复的方法 https://stackoverflow.com/a/10127787/643500

关于java - 加载图像时出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10436927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com