0

I am taking an image from gallery converting it into a bitmap and sending it through intent but I am unable to get High-resolution image.

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CANCELED) {
        return;
    } else if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK) {


        uriImage = data.getData();


        Intent intent = new Intent(MainActivity.this, CropActivity.class);
        intent.putExtra("uri", uriImage);
        startActivity(intent);

in second Activity

  Uri uriImage = getIntent().getParcelableExtra("uri");

    if (uriImage != null) {
        try {
           bitmap= MediaStore.Images.Media.getBitmap(this.getContentResolver(), uriImage);

        } catch (Exception e) {
            e.printStackTrace();
        }

    } 
  • what do you mean by high-resolution image? – Tara Nov 19 '18 at 09:27
  • @WaleedAsim i have an image size of 9MB when i selected my app crashed – Qasim Abbasi Nov 19 '18 at 09:36
  • can you send me your logcat error – Tara Nov 19 '18 at 10:58
  • check this https://stackoverflow.com/questions/14998687/android-large-images-cause-app-crash – Tara Nov 19 '18 at 10:59
  • @WaleedAsim11-19 16:16:12.161 21889-21889/developers.berry.com.policesuit E/AndroidRuntime: FATAL EXCEPTION: main Process: developers.berry.com.policesuit, PID: 21889 java.lang.OutOfMemoryError: Failed to allocate a 96000012 byte allocation with 16777120 free bytes and 37MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) – Qasim Abbasi Nov 19 '18 at 11:17
  • check my answer – Tara Nov 19 '18 at 11:21
  • @WaleedAsim not working – Qasim Abbasi Nov 19 '18 at 11:37

2 Answers2

0
private ArrayList<Image> imagesList = new ArrayList<>();  

select the image :

 ImagePicker.create(UploadPhotosActivity.this)
            .showCamera(false)
            .limit(1)
            .imageTitle(getString(R.string.select_image))
            .folderTitle(getString(R.string.folder))
            .theme(R.style.ImagePickerTheme)
            .start(RC_CODE_PICKER);

onActivityResult :

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == RC_CODE_PICKER) {
            Log.d("===uploadPhoto", "gallery : " + data);
            imagesList = (ArrayList<Image>) ImagePicker.getImages(data);
            Intent intent = new Intent(UploadPhotosActivity.this, ImageCropperActivity.class);
            intent.putExtra("selectedImage", imagesList);
            startActivity(intent);
        }
    } else {
        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_CANCELED, returnIntent);
        finish();
    }
}

In second Activity :

        images = getIntent().getParcelableArrayListExtra("selectedImage);
Kevin Kurien
  • 798
  • 4
  • 14
0

Try this in your manifest!

<application
    android:allowBackup="true"
    android:hardwareAccelerated="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

Source

Tara
  • 671
  • 4
  • 18
  • "Failed to allocate a 96000012 byte allocation with 16777216 free bytes and 62MB until OOM" D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: developers.berry.com.mensuit, PID: 24073 java.lang.OutOfMemoryError: Failed to allocate a 96000012 byte allocation with 16777216 free bytes and 62MB until OOM – Qasim Abbasi Nov 19 '18 at 11:38
  • did you check source link? – Tara Nov 19 '18 at 11:44