Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Camera Set Resolution

Tags:

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 640x348 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();
    }
like image 480
Matt Avatar asked Jan 05 '12 15:01

Matt


People also ask

How do I check image resolution on Android?

Step one: When you find your image, don't open it. Instead, right click on the photo and select “Properties.” Step two: Once you're in “Properties,” click on the “Details” tab. Step three: Scroll until you see the resolution or dpi of your picture.


1 Answers

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.

like image 63
CommonsWare Avatar answered Nov 07 '22 01:11

CommonsWare