如何将资源添加为文件路径

时间:2013-09-27 11:57:01

标签: android

我使用下面的代码来解决内存问题。我的图像存在于名为123.jpg的res / drawable中。我正在按照下面的教程

http://android-solution-sample.blogspot.com/2011/10/bitmap-out-of-memory.html

 BitmapFactory.Options o = new BitmapFactory.Options();

 o.inJustDecodeBounds = true;

 FileInputStream fis = new FileInputStream(files[i].getAbsolutePath());
 BitmapFactory.decodeStream(fis, null, o);
 fis.close();
 final int REQUIRED_SIZE = 70;
 int width_tmp = o.outWidth, height_tmp = o.outHeight;
 int scale = 1;
 while (true) {
     if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
         break;
     width_tmp /= 2;
     height_tmp /= 2;
     scale *= 2;
 }
 BitmapFactory.Options op = new BitmapFactory.Options();
 op.inSampleSize = scale;
 fis = new FileInputStream(files[i].getAbsolutePath());
 bitmap = BitmapFactory.decodeStream(fis, null, op);
 fis.close();

0 个答案:

没有答案