camera-preview icon indicating copy to clipboard operation
camera-preview copied to clipboard

Preview not resized and displayed correctly when orientation changes

Open anth0 opened this issue 4 years ago • 17 comments

Describe the bug Camera preview is not resized and displayed correctly when changing device's orientation.

To Reproduce Steps to reproduce the behavior:

  1. Start the camera with the device in portrait
  2. Rotate the device to landscape

Expected behavior Displayed preview should be resized according to landscape as it would be if the camera was started with the device in landscape.

Screenshots Current portrait Current when changed to landscape Current when started in landscape

Smartphone (please complete the following information):

  • Device: Pixel 3 XL
  • OS: Android
  • Version: API R

Additional context Add any other context about the problem here.

anth0 avatar Feb 08 '21 18:02 anth0

Same thing happens on my iPhone XS. Have you tried window.screen.orientation.lock('landscape'); ?

gbrits avatar Feb 15 '21 12:02 gbrits

For iOS there is the rotateWhenOrientationChanged property that can be set on the CameraPreviewOptions on the plugin. This seems to work fine for iOS but there is no similar property for Android.

I don't want to lock the orientation in my app as I want users to be able to take pictures either in portrait or landscape.

anth0 avatar Feb 15 '21 12:02 anth0

In my case, I want the orientation not to change out of landscope mode - does rotateWhenOrientationChanged set to false (that's its default right?) make a difference?

gbrits avatar Feb 15 '21 12:02 gbrits

/** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */ rotateWhenOrientationChanged?: boolean;

So you should try setting it to false manually. Also, if your app should always be used in landscape then I'd suggest blocking orientations natively within xcode for the whole app.

anth0 avatar Feb 15 '21 12:02 anth0

Thanks for that, and yes I have locked it to landscape, but it was loading initially as portrait & then switching to landscape, and the switch is customer-visible. But I will test it now with the rotateWhenOrientationChanged boolean applied & see if it fixed it up.

gbrits avatar Feb 15 '21 13:02 gbrits

This is a known limitation. Setting rotateWhenOrientationChanged prop to false should help until this is fixed.

ryaa avatar Feb 16 '21 11:02 ryaa

Turns out that removing these settings:

    // width: window.screen.width,
    // height: window.screen.height,

made the following difference on my iPhone:

Before: https://ibb.co/h19gtX8 After: https://ibb.co/h19gtX8

gbrits avatar Feb 16 '21 12:02 gbrits

So perhaps the calculation on window screen width / height is inaccurate against orientation.

gbrits avatar Feb 16 '21 12:02 gbrits

@gbrits I don't set width and height and have a correct behaviour on iOS. Here are my properties:

private static cameraPreviewOptions: CameraPreviewOptions = { position: 'rear', toBack: true, rotateWhenOrientationChanged: true, enableHighResolution: true, parent: 'cameraPreview', className: 'cameraPreview' };

private static captureOptions: CameraPreviewPictureOptions = { quality: 100, width: 2500, height: 5000 };

@ryaa you say it's a known limitation but are you referring to gbrits' issue or mine with Android?

anth0 avatar Feb 16 '21 13:02 anth0

Hey @anth0 that's precisely what I did, removed those settings. The issue I was encountering was as a result of having those two settings set

gbrits avatar Feb 16 '21 13:02 gbrits

Hey while we're all here & talking -- is there any way to force the torch on?

gbrits avatar Feb 16 '21 13:02 gbrits

@ryaa you say it's a known limitation but are you referring to gbrits' issue or mine with Android?

I refer to the problem with the preview when the orientation is changed.

ryaa avatar Feb 16 '21 15:02 ryaa

Hey while we're all here & talking -- is there any way to force the torch on?

yes. use this method https://github.com/capacitor-community/camera-preview#setflashmodeoptions with 'torch' value as the param

ryaa avatar Feb 16 '21 15:02 ryaa

This PR should fix it https://github.com/capacitor-community/camera-preview/pull/238

I would appreciate if someone could test this and my other fixes (https://github.com/capacitor-community/camera-preview/issues/228 and https://github.com/capacitor-community/camera-preview/issues/232) installing from here npm install ryaa/camera-preview#chore/test-latest-fixes-as-of-20-july-2022

ryaa avatar Jul 20 '22 16:07 ryaa

@ryaa I can not get to npm install ryaa/camera-preview#chore/test-latest-fixes-as-of-20-july-2022

orest avatar Jul 25 '22 22:07 orest

ryaa/camera-preview#chore/test-latest-fixes-as-of-20-july-2022

Can you please try ryaa/camera-preview#chore/my-latest-fixes-as-of-21-july-2022 It includes fixes for iOS (https://github.com/capacitor-community/camera-preview/issues/232) and Android (this ticket). Thank you.

ryaa avatar Jul 26 '22 04:07 ryaa

fix for issue 232 looks good. Tested both iOS and Android. Thank you very much for the fix.

orest avatar Jul 26 '22 05:07 orest