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

Preview is always 90 degree off #9

Open
aftabnaqvi opened this issue May 24, 2016 · 2 comments
Open

Preview is always 90 degree off #9

aftabnaqvi opened this issue May 24, 2016 · 2 comments

Comments

@aftabnaqvi
Copy link

Thanks for providing the great start sample with camera APIs.

On my Samsung Galaxy S4, preview is always 90 degrees off. It happens in both Landscape and portrait mode.

Any tips would be helpful.

@stevealbertwong
Copy link

how did you run the app? I have having a lot of errors

@joxad
Copy link

joxad commented Aug 10, 2016

Hi guys, follwing differents tutos on the web I found the problem for the camera preview

I just copy past the NativeCameraFragment in my project.

Update the optimatePreviewSize method, on my LGG3, the existing one gave me null size
With the following method it works fine for me

`
/**
*
* @param sizes
* @param width
* @param height
* @return
*/
private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int width, int height)
{
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) height / width;

        if (sizes == null)
            return null;

        Camera.Size optimalSize = null;
        double minDiff = Double.MAX_VALUE;

        int targetHeight = height;

        for (Camera.Size size : sizes) {
            double ratio = (double) size.height / size.width;
            if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
                continue;

            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }

        if (optimalSize == null) {
            minDiff = Double.MAX_VALUE;
            for (Camera.Size size : sizes) {
                if (Math.abs(size.height - targetHeight) < minDiff) {
                    optimalSize = size;
                    minDiff = Math.abs(size.height - targetHeight);
                }
            }
        }

        return optimalSize;
    }
}

`

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

3 participants