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 size is not correctly calculated in Portrait mode #275

Open
johnbyrne7 opened this issue Jan 20, 2023 · 6 comments · May be fixed by #339
Open

Preview size is not correctly calculated in Portrait mode #275

johnbyrne7 opened this issue Jan 20, 2023 · 6 comments · May be fixed by #339

Comments

@johnbyrne7
Copy link
Contributor

johnbyrne7 commented Jan 20, 2023

When I use camera preview in portrait mode on Android, the size/aspect ratio is not correctly calculated. The side edges of the preview are cut off, compared to what the regular camera shows.

I see these values in the log, which are obviously not correct, as they are the same values for width and height

optimal preview size: w: 1088 h: 1088

I believe this is because targetHeight is set to surface height, and then used to both discover available camera aspect ratios, and if no suitable one is not found, targetHeight only is used to find a match.

I made a quick test change to set targetHeight to surface width when in portrait mode, leaving the rest of the logic alone, and that seemed to work.

After this change, I see this in the log:

optimal preview size: w: 1920 h: 1080

and, the preview sides are now visible.

Code changed in Preview.java

private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
int targetHeight = h;
if (displayOrientation == 90 || displayOrientation == 270) {
targetRatio = (double) h / w;
targetHeight = w;
}

@FernetB
Copy link

FernetB commented Feb 13, 2023

Same here, seems impossible to me to get the same size preview that in the capturaSample method (with Capture is even worse)

I don't know what to do and I think this repo is already dead

@pbowyer is this still maintained?

@pbowyer
Copy link
Collaborator

pbowyer commented Feb 13, 2023

@FernetB It's not maintained. I have no free time at present to merge PRs, let alone give them the proper testing users deserve. And my contract to develop a company's app that uses this plugin has finished, so I don't get any work time to give to it.

@riderx
Copy link
Contributor

riderx commented Feb 24, 2023

Can you try @capgo/camera-preview ? i believe the problem is not there, otherwise i can fix it

@HuyHHV
Copy link

HuyHHV commented Apr 13, 2023

Hello! It's quite late, so I'm not sure if you still need it. I think the width and height options only accept integer values. If you provide a value with a decimal number, it will default to the screen width or height. So the solution is rounding them up

@pablo-draxu
Copy link

@riderx, I just tested, and the same problem occurs in @capgo/camera-preview. It would be awesome if you can fix it there.

@algopert
Copy link

algopert commented Aug 6, 2023

Same issue!

@dpa99c dpa99c linked a pull request Jun 22, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

7 participants