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
Highlighted
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus
Accepted Solution

change Camera Flash Mode without restarting the viewfinder,

Hi, is it possible to change the camera flash mode without restarting the viewfinder?

 

Thank you!

 

void CameraTest::changeFlashMode()
{
	if(currentFlashMode==CameraFlashMode::Off)
	{
		currentFlashMode=CameraFlashMode::On;
	}
	else if (currentFlashMode==CameraFlashMode::On)
	{
		currentFlashMode=CameraFlashMode::Auto;
	}
	else if(currentFlashMode==CameraFlashMode::Auto)
	{
		currentFlashMode=CameraFlashMode::Off;
	}

	cameraSettings->setFlashMode(currentFlashMode);
	camera->applySettings(cameraSettings);
        camera->open();

}

 

jayvdiyk.com
Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: change Camera Flash Mode without restarting the viewfinder,

You don't need that last line in your code.

 

if(currentFlashMode==CameraFlashMode::Off)
	{
		currentFlashMode=CameraFlashMode::On;
	}
	else if (currentFlashMode==CameraFlashMode::On)
	{
		currentFlashMode=CameraFlashMode::Auto;
	}
	else if(currentFlashMode==CameraFlashMode::Auto)
	{
		currentFlashMode=CameraFlashMode::Off;
	}
cameraSettings->setFlashMode(currentFlashMode); camera->applySettings(cameraSettings);

 

 will work just fine!

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: change Camera Flash Mode without restarting the viewfinder,

True, but the viewfinder will be restarted.

 

I need a solution where the viewfinder doesnt get restarted, like the one in the Native camera app.

 

Any ideas??

jayvdiyk.com
Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: change Camera Flash Mode without restarting the viewfinder,

[ Edited ]

When I change the settings on QML, the camera viewfinder doesn't need to be restarted. I don't know about doing it on C++,  and if it does restart without the last line, then hopefully someone else can jump in and help.

 

Good luck!

 

Edit: I'de read some of the Camera API, and nothing says that doing

 

// Use the camera pointer to get
// the current settings.
cameraObj->getSettings(settings);
  
// You must cast newFlashMode to a CameraFlashMode::Type
// to pass it to the setFlashMode function.
settings->setFlashMode(CameraFlashMode::Type(newFlashMode)); cameraObj->applySettings(settings);

 will force a restart of the viewfinder.

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: change Camera Flash Mode without restarting the viewfinder,

[ Edited ]

Thanks, It works.

I had to add the following line.
cameraObj->getSettings(cameraSettings);

I wonder why though, since I have the reference to the cameraSettings ever since the app started. Any thoughts??

jayvdiyk.com
Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: change Camera Flash Mode without restarting the viewfinder,

Awesome, remember to mark the solution to close the thread. And to answer your post-question, you need to repopulate cameraSettings immediately before making changes to any of the camera's settings. Any old CameraSettings object will become "practically" useless when there's a change to the settings, since it's out of sync with actual state of the settings.

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: change Camera Flash Mode without restarting the viewfinder,

Well explained, thanks!
jayvdiyk.com