BitmapFactory.decodeFile(picturePath,options)导致空点异常

时间:2016-03-31 08:18:26

标签: android bitmapfactory

我正在尝试将库中的选定图像加载到imageView中。我设法用小图片做到了。当我选择更大的图片时,应用程序将关闭,它将显示java.out.of.memory。在谷歌搜索后,我发现我可以为decodeFile添加一个选项,但它会导致零点异常。这是我的编码。

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
    Uri selectedImage = data.getData();
    String[] filePathColumn = { MediaStore.Images.Media.DATA };

    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    cursor.moveToFirst(); //TODO google

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;

    ImageView imageView = (ImageView) findViewById(R.id.imageView);
    Bitmap temp = null;
    temp=BitmapFactory.decodeFile(picturePath, options);
    float ratio = temp.getWidth()/temp.getHeight();
    int width = 480;
    int height = Math.round(width/ratio);
    pic = Bitmap.createScaledBitmap(temp, width, height, false);
    imageView.setImageBitmap(pic);
}

没有temp = BitmapFactory.decodeFile(picturePath,options);中的选项,我无法打开大尺寸图片,其中包含temp = BitmapFactory.decodeFile(picturePath,options);中的选项,我得到了零点异常。

0 个答案:

没有答案