Greeting
I have done a camera intent, passing the file parameter to get the full sized image, also I have a function to scale the image and set it in the UI.
How ever, I want to know the resolution with which the user took the photo. Is there anyway to know the resolution user choose?
I want to know this cause my app is crashing in poor hardware devises with hiqh quality resolution. Any photo above 2M pixels will crash older phones.
I know the real solution is to improve performance of JAVA memory in overall application. But this will be a quickfix and I will see the other later. Also, 1.something M pixel for photo is enough. Is just part of a checklist that doesnt need to be in bether quality.
Is there anyway to know the resolution the camera used?
Thanks.
EDIT: Thanks everybody for your answers but I have to admit, I neglict mi explanation. Another reason why I want to simply get the resolution is cause the app also transform the URI path in to a content path, so if the photo has too much quality for the phone to handle it, its crash. I only want to warn the user if the resolution is too high, so how could I know every appropiate resolution for every phone, instead of it I just catch the error "java.langOutOfMemory" and that will warn the user. Like this:
try {
//here is my method to convert uri path to content
} catch (OutOfMemoryError outOfMemoryError) {
Toast toast = Toast.makeText(getApplicationContext(), "Please lower photo resolution", Toast.LENGTH_LONG);
toast.show();
}
You can cast the result to a Bitmap:
Bitmap temp = BitmapFactory.decodeFile(data.getData().getPath());
then you can get the resolution like this:
temp.getWidth();
temp.getHeight();
or you could do this:
BitmapFactory.Options temp = new BitmapFactory.Options();
temp.inJustDecodeBounds = true;
BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, temp);
int width = temp.outWidth;
int height = temp.outHeight;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.