Reputation: 646
im developing an app that allows users to take a picture and then it does some work on it in the background, however i have run into a problem i have hard coded the picture size into it and it is causing errors on a different phone to the one i am using and im assuming its down to the phone not supporting the camera size i have hard coded.
i have read on here about it but the answers are to vague all people keep saying is to use the getSupportedSizes method but i just dont know what to do with it after that.
any help would be greatly appreciated.
Upvotes: 1
Views: 10318
Reputation: 28389
It's important to use this method because the cameras on the different devices support very different resolutions, so, you'll have to specify what resolution you want out of the ones that are available on the given device.
Pseudo....
Camera.Parameters cp = mCamera.getParameters();
List<Size> sl = cp.getSupportedPictureSizes();
//now that you have the list of supported sizes, pick one and set it back to the parameters...
int w,h;
for(Size s : sl){
//if s.width meets whatever criteria you want set it to your w
//and s.height meets whatever criteria you want for your h
w = s.width;
h = s.height;
break;
}
cp.setPictureSize(w, h);
mCamera.setParameters(cp);
Usually the thing that matters most is the photo's aspect ratio. So, you'll want to compare the w/h to 16:9 or 4:3 and then find the highest (or second highest) quality at the supported ratio. Obviously, I don't know what your needs are so you'll have to determine what sizes actually meet your given criteria. If you simply want the highest quality and you don't care about the aspect ratio you'll usually find that as the last item in the list of sizes.
Upvotes: 6