Android Camera Set Resolution

android

I have built a custom Camera App and I am trying to change the resoloution of the image that is took. I have read around that this could depend on the phone or version of Android?

I know they are set using the setParameters but just dont know how to set the actuall resoloution to work on all phones. I am wanting it to be kind of small as my app force closes otherwise. When I use a test picture at 640×348 this works so around that size/resoloution would be perfect.

It may be easier to use setPictureSize?

public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera = Camera.open();
    try {
           Camera.Parameters parameters = camera.getParameters();
           if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
              parameters.set("orientation", "portrait");
              camera.setDisplayOrientation(90);
              // Uncomment for Android 2.0 and above
              parameters.setRotation(90);
           } else {
              parameters.set("orientation", "landscape");
              camera.setDisplayOrientation(0);
              // Uncomment for Android 2.0 and above
              parameters.setRotation(0);
           }
          camera.setParameters(parameters);
          camera.setPreviewDisplay(holder);
      } catch (IOException exception) {
         camera.release();
       }
        camera.startPreview();
    }

Best Solution

There is no setResolution(), only setPictureSize(). Use getSupportedPictureSizes() on Camera.Parameters to find the size you want, or use that information to populate a ListView or Spinner or something for the user to choose the desired size. Here is a sample project recently updated to use getSupportedPictureSizes() to find the smallest supported resolution and use that.