3

For my project requirement, I am using Google's camera2 api basic example and I don't want to restart my activity on orientation change. But, while doing this I face an issue that If i change my view from portrait to landscape mode camera preview is not redrawn and aspects of portrait are applied in landscape mode. Due to this when i capture image, Camera captures larger image then what is shown on preview in landscape mode.

Reproduction steps :
Pre condition :
Handle onOrientationChange in manifest file for the activity.
Steps:
1. Open camera in portrait mode and then rotate to landscape mode
2. Capture image

For this, I called closeCamera() and then openCamera() in onConfigurationChanged() but it is not a good solution beacuse it takes a lot of time to recreate everything. Is there any way I can redraw the preview surface ?

nits.kk
  • 5,204
  • 4
  • 33
  • 55
Agam Goyal
  • 31
  • 2
  • Possible duplicate of [Rotating a Camera SurfaceView to portrait](https://stackoverflow.com/questions/7455399/rotating-a-camera-surfaceview-to-portrait) – Kiran Maniya Sep 14 '19 at 08:56
  • `"I don't want to restart my activity on orientation change"`. You can't do it because it's a lifecycle. for the orientation issue refer to I don't want to restart my activity on orientation change – Kiran Maniya Sep 14 '19 at 08:58
  • you should also post your relevant code. Also did you check the camera2api basic sample from google? – Raghunandan Sep 14 '19 at 09:12
  • 1
    @Raghunandan yes I am using camera2api basic sample. I just added android:configChanges="orientation|screenSize|keyboardHidden" in CameraActivity tag in android manifest – Agam Goyal Sep 14 '19 at 15:47
  • @Kiran Maniya No, it is a different issue than Rotating a Camera SurfaceView to portrait. – Agam Goyal Sep 14 '19 at 15:55
  • 1
    @Raghunandan If you run the sample with my changes in emulator you will see that when you change the orientation from portrait to landscape while camera preview is showing, the animation gets out of the screen . This shows that when I will capture the image, more area will be covered in image than what is actually showing on camera preview – Agam Goyal Sep 14 '19 at 15:55
  • @AgamGoyal do you use fragment and do you retain the fragment?. If not can you try using fragment and retaining it. – Raghunandan Sep 14 '19 at 16:22
  • 1
    @Raghunandan Yes, I am using fragment as used in the example. And it is retained and it would be retained as cameraActivity is not recreated so fragment will also be retained – Agam Goyal Sep 14 '19 at 16:34

0 Answers0