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

Java Development

Reply
Highlighted
Contributor
Posts: 15
Registered: ‎04-19-2011
My Device: Torch
Accepted Solution

Invoking camera in application

Hi Friends,

 

I am working with blackberry os 4.2.I am taking a snapshot using a video player in my app and showing a preview of the image in my screen.But unfortunately, the image is shown fine on the simulator(Blackberry Tour 9630) but on the phone that screen is never displayed.I attach the code below:

 

This is how i initialize the camera:

private byte[] initializeCamera()

{

try

{

player = Manager.createPlayer( "capture://video?encoding=jpeg&width="+width+"&height="+height+"&quality=normal");

 //width and height are retrieved from the encoding.Anything <=640x480 is selected.

player.realize();

 

_videoControl = (VideoControl)player.getControl( "VideoControl");

 

if (_videoControl != null)

{

// Create the video field as a GUI primitive (as opposed to a// direct video, which can only be used on platforms with LCDUI support.

_videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");

 

_videoControl.setDisplayFullScreen(true);

 

_videoControl.setVisible(true);

}

player.start();

 

}

catch(Exception e)

{

Dialog.inform(

"ERROR 2" + e.getClass() + ": "+ e.getMessage());

}

if(_videoField!=null) {

 

returnraw;

}

else{

 

returnnull;

}

}

 

And when the user clicks i implement this function:

 

public

voidtakePicture()

{

try

{

 

 

raw = _videoControl.getSnapshot( null);

 

player.close();

createImageScreen(raw);

 

// layThisSet();// addComponents();

 

}

catch(Exception e)

{

}

}

 

The createImageScreen function passes the byhte array to another screen class which does the display as follows:

 

Bitmap bm = Bitmap.createBitmapFromBytes(raw, 0, -1, 1 );

 

 

 

int scalingWidth = (int) Math.ceil((bm.getWidth()*2.0)/(Display.getWidth()*1.0));

 

int scalingHeight = (int) Math.ceil((bm.getHeight()*5.0)/(Display.getHeight()*2.0));

 

Bitmap scaledImage = Bitmap.createBitmapFromBytes(raw, 0, -1, scaling );

 

imageField= new BitmapField( image );

//

 

 This code works fine and the image is displayed correctly on the simulator but not on the device the execution seems to reach only till the first Bitmap.createBitmapBytes() above.Please help.This is very important for my project.

Developer
Posts: 654
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers

Re: Invoking camera in application

Make sure you have set the Permission for Recording to ALLOW....can't capture screen without it.

 

Hope that helps.


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Contributor
Posts: 15
Registered: ‎04-19-2011
My Device: Torch

Re: Invoking camera in application

Hi Steven,

 

The permission is explicitly asked for by the device when before the picture is captured.And I always set it to allow.But it still doesnt solve the problem..

BlackBerry Development Advisor
Posts: 15,300
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Invoking camera in application

Support for capturing a screen shot was added in BlackBerry device software version 4.3.0.  It is not supported in 4.2.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker