Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
smiley
Posts: 1,473
Registered: ‎07-14-2008
My Device: Z10
Accepted Solution

How to adjust the camera preview when screen is rotated?

I have a ForeignWindowControl with the camera control and when I rotate the device the UI controls on the screen are redrawn correctly but the preview camera is not properly rotated.  looks weird.


Do I have to set the ForeignWindowControl size on rotate completed if so how?

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: How to adjust the camera preview when screen is rotated?

can you post a pair of screenshots?

You mentioned using ForeignWindowControl, but then you also mentioned the Camera control.  Are you using the C native camera API, or the cascades Camera?  I'm just a bit confused because I thought the Cascades Camera took care of all the FWC control details.

Please use plain text.
Developer
smiley
Posts: 1,473
Registered: ‎07-14-2008
My Device: Z10

Re: How to adjust the camera preview when screen is rotated?

I'm using C++ and adding cascade controls manually vs qml.

 

In the Page I have a container(ForeignWindowControl and a button on the bottom left corner).

 

When I rotate to landscape the button is redrawn correctly but the camera preview is strettched and looks weird.

I want to the camera preview behave like the native camera app when changing orientations.

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: How to adjust the camera preview when screen is rotated?

okay.  the co-ordinate reference for the display was rotated, so you need to apply a screen window rotation to your viewfinder window handle.  that should sort it out.  I'm assuming you are seeing a sideways compressed viewfinder.

 

Please use plain text.
Developer
smiley
Posts: 1,473
Registered: ‎07-14-2008
My Device: Z10

Re: How to adjust the camera preview when screen is rotated?

[ Edited ]

ok. thanks

 

edit: Half way there.  The problem i'm having now is determine the direction.  In the slot it passes the var bb::cascades::UIOrientation::Type uiOrientation

 

how do I tell which direction the device was rotated?

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: How to adjust the camera preview when screen is rotated?

take a look here:

https://developer.blackberry.com/cascades/reference/bb__cascades__orientationsupport.html

 

I believe displayDirection is the value you want to look for.  The value in degrees is either the amount you need to rotate the window by, or the complementary angle.. just experiment to see which one it is.

 

Cheers,

Sean

Please use plain text.
Developer
smiley
Posts: 1,473
Registered: ‎07-14-2008
My Device: Z10

Re: How to adjust the camera preview when screen is rotated?

I thought have the problem solved but it is still there.

 

When I start the camera in portrait mode and then rotate to right the preview is still showing in portrait and is not rotated like the native camera.

 

I have some controls overlay and I have them rotated correctly.

When my app detects orientation change I do this

 

1. set the viewfinder property

 

        screen_set_window_property_iv(mViewfinderWindow->windowHandle(), SCREEN_PROPERTY_ROTATION, &angle);

 

2. set the video property

 

        camera_set_videovf_property(mCameraHandle,
                                        CAMERA_IMGPROP_ROTATION,  angle);

 

and all i get is a black screen.

 

 

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: How to adjust the camera preview when screen is rotated?

Do you need the pixels coming from the camera to be rotated?  (eg. for a video recording)  or is this strictly a viewfinder?

if it's only a viewfinder, then I would suggest not bothering to reconfigure CAMERA_IMGPROP_ROTATION, and I would just tweak the screen window settings appropriately: swap width & height and apply a window rotation.

 

If you actually need to reconfigure the viewfinder pixel rotation via CAMERA_IMGPROP_ROTATION (eg. for recording), then you should not need to rotate the screen window.. just swap w & h.

 

The first solution is what the BB10 camera app does when you rotate the device in video mode, but once you need to start recording, it takes the second approach to re-orient the buffers so that they can be fed to the mp4 encoder correctly.

 

I'm not sure why you would be getting a black screen back.  Can you try only doing the CAMERA_IMGPROP_ROTATION change and see what happens?  (you should just see a squashed viewfinder as a result).

Please use plain text.
Developer
smiley
Posts: 1,473
Registered: ‎07-14-2008
My Device: Z10

Re: How to adjust the camera preview when screen is rotated?

The first problem I have is when I rotate the viewfinder (camera preview screen) is not roated. 

Second when I do record the video it is in the wrong orientation.

 

If I leave everything as is then my controls on the overlay are not rotated.  That is when I add

 

        screen_set_window_property_iv(mViewfinderWindow->windowHandle(), SCREEN_PROPERTY_ROTATION, &angle);

I'm not using Cascade camera control. 

 

I will try your suggestion.  thanks

 

Please use plain text.
Developer
smiley
Posts: 1,473
Registered: ‎07-14-2008
My Device: Z10

Re: How to adjust the camera preview when screen is rotated?

HI Sean,

 

My problem now is that the recording is wrong when recording in landscape.

 

My setting is 480 x 640 for portrait.  When i wipe the wid and hi and set it it returns error because 640 x 480 is not one of the support mode.

 

            if (camera_set_videovf_property(mCameraHandle,
                                            CAMERA_IMGPROP_WIDTH, wid,
                                            CAMERA_IMGPROP_HEIGHT, hi) != 0)

What is the correct way to reset the screen resolution?  thanks

 

 

 

Please use plain text.