解决java.lang.OutOfMemoryError: bitmap size exceeds VM 方式
当图片过大,或图片数量较多时使用BitmapFactory解码图片会出java.lang.OutOfMemoryError: bitmap size exceeds VM budget,要想正常使用则需分配更少的内存,具体的解决办法是修改采样值BitmapFactory.Options.inSampleSize,例如:
BitmapFactory.Options opts = new BitmapFactory.Options();opts.inJustDecodeBounds = true;BitmapFactory.decodeFile(imageFile, opts);opts.inSampleSize = computeSampleSize(opts, -1, 128*128);opts.inJustDecodeBounds = false;try {Bitmap bmp = BitmapFactory.decodeFile(imageFile, opts);imageView.setImageBitmap(bmp); } catch (OutOfMemoryError err) {}