Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default camera picture size has lower resolution than preview size. #46

Open
HugoMatilla opened this issue Feb 29, 2016 · 1 comment
Open

Comments

@HugoMatilla
Copy link

Alternative title "Option to get and update camera parameters"
Hi @livotov first, thanks for your work on this Library.

In some devices when taking a picture, the resulting picture has really small resolution although the preview looks good.
After some searching I found that parameters.getPictureSize() is different to parameters.getPreviewSize() . So the preview image can look ok, but the photo taken has really low resolution.

It is because the default parameters gotten from the camera are set to this low resolution values. They are the default settings point 2 on the list and I could not find how are they set in the device or where they come from. It is something that the user set on its device?, or it depends on the device itself? I have a list of the devices where I found this issue and there are from low to top quality devices, so I would say that is more a user thing than a device.

Is this a problem?
Is the library intention to behave this way?

If the answer is no, to fix this specific problem, setting proper picture size when it is lower than the preview size, I added some methods to the DefaultCameraV1Controller I let them here and if you think they are ok I can make a pull request.

private void updatePictureSizeIfPreviewSizeIsBigger() {
    Camera.Parameters parameters = CameraUtilsV1.getMainCameraParameters(rawCameraObject);
    if (isPreviewSizeBiggerThanPictureSize(parameters)) {
        Size betterPictureSize = getClosestSupportedPictureSizeToPreviewSize(parameters);
        parameters.setPictureSize(betterPictureSize.width, betterPictureSize.height);
        rawCameraObject.setParameters(parameters);
    }
}

private boolean isPreviewSizeBiggerThanPictureSize(Camera.Parameters parameters) {
    boolean widthOk = parameters.getPreviewSize().width <= parameters.getPictureSize().width;
    boolean heightOk = parameters.getPreviewSize().height <= parameters.getPictureSize().height;
    return !(widthOk && heightOk);
}

private Size getClosestSupportedPictureSizeToPreviewSize(Camera.Parameters parameters) {
    Size result = new Size(0, 0);
    int previewHeight = parameters.getPreviewSize().height;
    int previewWidth= parameters.getPreviewSize().width;

    List<Camera.Size> pictureSizes = parameters.getSupportedPictureSizes();
    for (Camera.Size size : pictureSizes) {
        if (size.height >= previewHeight && size.width >= previewWidth) {
            result.height = size.height;
            result.width = size.width;
        }
    }
    return result;
}

private static class Size {
    public  int width;
    public  int height;
    public Size(int width, int height) {
        this.width = width;
        this.height= height;
    }
}

I added updatePictureSizeIfPreviewSizeIsBigger() at the end of the startPreview method before the setupSurfaceAndCameraForPreview call

Another solution and an enhancement is to have access to the parameters of the camera, directly from the CameraLiveView.

I hope I was clear enough :)

Thanks again for your work.

@HugoMatilla HugoMatilla changed the title Default camera picture size is the smallest one in some cases. Default camera picture size has low resolution in some cases. Feb 29, 2016
@HugoMatilla HugoMatilla changed the title Default camera picture size has low resolution in some cases. Default camera picture size has lower resolution than preview size. Feb 29, 2016
@samy-baili
Copy link

Works for me, Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants