Ankit
Ankit

Reputation: 1148

Cwac-Camera out file size issue on specific devices

I am using CWAC - Camera library to integrate custom camera in my app.

It works fine as expected on all devices which i have, except on Moto E & Moto G.

When i capture Single Shot image with above devices, i don't get desired size output image.

When i go to capture SingleShot image, getLargestPictureSize (CameraUtils) method returns highest size which camera supports like 1944*2592 (h*w) and the same set in Camera parameters before capture but output file is generated with 1280*720 (h*w).

Can anyone guide me towards possible issue?

getLargestPictureSize method

public static Camera.Size getLargestPictureSize(CameraHost host,
                                                  Camera.Parameters parameters,
                                                  boolean enforceProfile) {
    Camera.Size result=null;

    for (Camera.Size size : parameters.getSupportedPictureSizes()) {

      // android.util.Log.d("CWAC-Camera",
      // String.format("%d x %d", size.width, size.height));

      if (!enforceProfile
          || (size.height <= host.getDeviceProfile()
                                 .getMaxPictureHeight() && size.height >= host.getDeviceProfile()
                                                                              .getMinPictureHeight())) {
        if (result == null) {
          result=size;
        }
        else {
          int resultArea=result.width * result.height;
          int newArea=size.width * size.height;

          if (newArea > resultArea) {
            result=size;
          }
        }
      }
    }

    if (result == null && enforceProfile) {
      result=getLargestPictureSize(host, parameters, false);
    }

    return(result);
  }

Capture method

public void takePicture(final PictureTransaction xact) {
    if (inPreview) {
      if (isAutoFocusing) {
        throw new IllegalStateException(
                                        "Camera cannot take a picture while auto-focusing");
      }
      else {
        previewParams=camera.getParameters();

        Camera.Parameters pictureParams=camera.getParameters();
        Camera.Size pictureSize=
            xact.host.getPictureSize(xact, pictureParams);

        pictureParams.setPictureSize(pictureSize.width,
                                     pictureSize.height);
        pictureParams.setPictureFormat(ImageFormat.JPEG);
//        pictureParams.setColorEffect(Parameters.EFFECT_MONO);
        if (xact.flashMode != null) {
          pictureParams.setFlashMode(xact.flashMode);
        }

        if (!onOrientationChange.isEnabled()) {
          setCameraPictureOrientation(pictureParams);
        }

        camera.setParameters(xact.host.adjustPictureParameters(xact,
                                                               pictureParams));
        xact.cameraView=this;

        camera.autoFocus(new AutoFocusCallback() {
            @Override
            public void onAutoFocus(boolean success, final Camera camera) {
                        postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    camera.takePicture(
                                            xact,
                                            null,
                                            new PictureTransactionCallback(xact));
                                } catch (Exception e) {
                                    android.util.Log.e(getClass()
                                            .getSimpleName(),
                                            "Exception taking a picture", e);
                                    // TODO get this out to library clients
                                }
                            }
                        }, xact.host.getDeviceProfile().getPictureDelay());
            }
        });


        inPreview=false;
      }
    }
    else {
      throw new IllegalStateException(
                                      "Preview mode must have started before you can take a picture");
    }
  }

Upvotes: 0

Views: 126

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

I can reproduce your problem. Most size requests are ignored. My guess is that this device, like some others, does not like my changing camera parameters on the fly. I am going to replace CWAC-Camera with a new library which will stop doing that, plus add support for Android 5.0's android.hardware.camera2 API. Hopefully, this problem will be fixed at that point.

I have filed an issue for this on the existing library, so I know to specifically work on this scenario.

Upvotes: 1

Related Questions