How can i resize image before loading to imageview after selecting from gallery/photos?. Otherwise large images are causing OOM issues.
SelectImageGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Image From Gallery"), 1);
}
}
Uri uri = I.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
As you facing OOM issue, you can remove this issue by
1) Decrease size of bitmap and
2) Increase size of app by changing in gradle.properties and AndroidManifest file
gradle.properties org.gradle.jvmargs=-Xmx1536m
Android Manifest android:largeHeap="true", android:hardwareAccelerated="true"
I finally made it to resolve it using glide as follows for those who might need it in future. Selecting Intent
Setting Image to Imageview Using Glide
refer to this answer
you can resize your bitmap like this
Try: