How to change camera resolution programmatically in Android

Last updated on February 23, 2013 by Dan Nanni

If you are building a custom Camera app on Android, the following is an Android code example that you may find useful. This code snippet allows you to change camera resolution programmatically. The code is applicable to Android API level 5 and higher.

When you adjust camera resolution, you should first check available camera resolutions supported by a given Android device hardware. Then choose one among them to fit your need.

mCamera = Camera.open();
Camera.Parameters params = mCamera.getParameters();

// Check what resolutions are supported by your camera
List<Size> sizes = params.getSupportedPictureSizes();

// Iterate through all available resolutions and choose one.
// The chosen resolution will be stored in mSize.
Size mSize;
for (Size size : sizes) {
    Log.i(TAG, "Available resolution: "+size.width+" "+size.height);
    if (wantToUseThisResolution(size)) {
        mSize = size;
        break;
    }
}

Log.i(TAG, "Chosen resolution: "+mSize.width+" "+mSize.height);
params.setPictureSize(mSize.width, mSize.height);
mCamera.setParameters(params);

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean