Reputation: 1
Ok, making a camera app and one part is selecting img size, done with following code:
Camera.Parameters parameters = camera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
I get a nice list with supported sizes. Two worst resolutions are 640x480 and 320x240. But when I set resolution to 320x240 that 640x480 is used instead!
I set the resolution with following code:
private void setImgSize()
{
Log.d(TAG, "+setImgSize");
Camera.Parameters params = camera.getParameters();
params.setPictureSize(WIDTH, HEIGHT);
camera.setParameters(params);
Toast.makeText(getApplicationContext(),
"Resolution set to "+WIDTH+"x"+HEIGHT,
Toast.LENGTH_SHORT).show();
}
WIDTH and HEIGHT are values returned from settingsactivity, and I get a nice Toast telling that resolution is set to 320x240. But when images are captured resolution is 640x480! Ok, test2. Let's set resolution to 640x480. Toast is telling that resolution is 640x480. Cool. Let's capture some images, and their resolution is 640x480 as defined!
So, what am I doing wrong here and/or what I don't understand?!?! I get supported image sizes and at least one of them is not supported. Is there any way to check if the selected resolution is actually supported?
Device I use is Huawei Ideos X5 / U8800 with Android version 2.3.5.
Thanks for help :)
P.S. And before someone asks why I want use such a crappy resolution, this is why: This app will capture images in N seconds interval. And if the application is running, let's say, very long time, I might run out of space in my sd card with large images :)
edit: changed that setImgSize()-method and now it looks like this:
private void setImgSize() {
Log.d(TAG, "+setImgSize");
Camera.Parameters params = camera.getParameters();
params.setPictureSize(WIDTH, HEIGHT);
// set jpeg quality to best
params.setJpegQuality(100);
camera.setParameters(params);
params = null;
params = camera.getParameters();
Camera.Size size = params.getPictureSize();
Toast.makeText(getApplicationContext(),
"Resolution set to "+size.width+"x"+size.height,
Toast.LENGTH_SHORT).show();
}
I set the resolution (320x240), and when I read it from re-read parameters result is that 320x240, but when image is captured resolution is 640x480 :(
Upvotes: 0
Views: 1310
Reputation: 2856
I think you should call getSupportedPictureSizes()
from Camera.Parameters
to know which image sizes are supported.
Then you can choose the supported image size which is closest to the one you actually want to set.
Upvotes: 1