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

Scaleing of preview box #663

Closed
capc0 opened this issue Dec 15, 2021 · 1 comment
Closed

Scaleing of preview box #663

capc0 opened this issue Dec 15, 2021 · 1 comment

Comments

@capc0
Copy link

capc0 commented Dec 15, 2021

Is it possible to scale the preview box?

For example the device screen is 800x400px.

The camera supported resolutions are 400x200px and 1200x600px.

If I choose the lower resolution 400x200px, the preview will not fill the entire screen

image

If I choose the higher resolution 1200x600px, the preview will be larger than the screen

image


Is there a positibility to choose the higher res 1200x600px but then scale the View-Container of the preview box, so that the entire screen is filled? It is ok if there is a little overlap top/bottom or left/right that is not visible due to aspect ratio.

image

@capc0
Copy link
Author

capc0 commented Dec 16, 2021

Instead of scaling, this can be achieved with the x, y, width, height params of startCamera in combination with setPreviewSize.

For future reference:

  • startCamera with x = 0, y = 0, width = window.innerWidth, height = window.innerHeight results in a view container that fits the entire screen. x, y, width and height can be any user defined pixel value.
  • setPreviewSize of e.g. 400x200px sets the camera to that resolution. It is than stretched into the dimensions above (low camera resolution but fullscreen). Aspect ratio may be distorted however. Width and height can only be a dimsension that is supported by the camera. Currently there only is the option to get the supported pictures sizes, but not all of them are working. A new method to get the supported preview sizes is therefore needed Feature request: getSupportedPreviewSizes #664
  • in order to keep the correct aspect ratio of the screen, the x, y, width and height params of setPreviewSize need to be calculated and adjusted (e.g. leave space for black bars on top and bottom OR move into negative pixel area and cut off some image content of the preview)

Edit: on iOS the implementation seems to work differently. Using window.innerWidth and window.innerHeight for startCamera without the use of setPreviewSize however seems to work for all iPhone/iPads.

@capc0 capc0 closed this as completed Dec 16, 2021
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

1 participant