public static Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
// Determine a size threshold below which compression is not performed
int sizeThreshold = 1024; // for example, consider images smaller than 1KB
if (inImage.getByteCount() > sizeThreshold) {
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
} else {
// Handle small images differently or skip compression
// For example, you might simply use the original image without compression
inImage.compress(Bitmap.CompressFormat.PNG, 100, bytes); // Use PNG format for small images
}
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
#Getting crash while compressing the image in Redmi devices. Android versions 10 mostly.