android.provider.MediaStore.Images.Media.getBitmap(cr,mImageUri)抛出内存不足异常

时间:2018-05-15 04:29:03

标签: android camera

单击相机中的图像后出现内存不足错误。获取位图的代码是:

public void grabImage(ImageView imageView) {
    this.getContentResolver().notifyChange(mImageUri, null);
    ContentResolver cr = this.getContentResolver();
    Bitmap bitmap = null;

    try {
        //getting crash on this line
        bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr,      mImageUri);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 50 / 100, byteArrayOutputStream);


        getImageUri(this, bitmap);

        imageView.setImageBitmap(bitmap);


    } catch (Exception e) {
        Toast.makeText(this, "Failed to load",Toast.LENGTH_SHORT).show();
        Log.d(TAG, "Failed to load", e);
    }catch (OutOfMemoryError e){
        e.printStackTrace();
    }

}

0 个答案:

没有答案