有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从Android Wear上的列表加载图像

我不熟悉java和Android Wear。这几天我一直在学习做表盘。我使用的是Android Studio 1.4.1

我有一个整数数组中要加载的图像列表

ImgFileIDs[0] = R.drawable.background
ImgFileIDs[1] = R.drawable.hour_hand
ImgFileIDs[2] = R.drawable.minute_hand
ImgFileIDs[3] = R.drawable.second_hand

我想反复浏览列表,并使用这个函数读取所有位图

for (int i=0; i<nImages; i++){
  Drawable backgroundDrawable;
  backgroundDrawable = resources.getDrawable(ImgFileIDs[i], null);
  TempBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
  Imgs.add(TempBitmap);
}

这失败了。。。 JAVAlang.OutOfMemoryError:无法分配4410012字节的分配,其中有1504948个可用字节和1469KB的内存

但是,将ImgFileIDs[i]中的i索引替换为ImgFileIDs[0]

  backgroundDrawable = resources.getDrawable(ImgFileIDs[0], null);

这是。。。但很明显,我只能访问一张图像。有什么提示吗

编辑: 因此,图像加载的大小似乎比源图像大

debug info 安卓工作室截图

调试信息显示图像是700x700。。。然而,源文件仅为400x400 32位png

为什么它会为位图图像分配超出必要的内存


共 (0) 个答案