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
Contributor
Posts: 11
Registered: ‎12-10-2010
My Device: Not Specified
Accepted Solution

Capturing Screenshot using touch screen devices

Hello Friends,

 

I have and requirement to capture the blackberry screenshot. I can do it using the class net.rim.device.api.system.Display as follows:

 

Bitmap screenBitmap=new Bitmap(Display.getWidth(),Display.getHeight());
Display.screenshot(screenBitmap);

 

But in case of touch screen devices when the on-screen keyboard is visible the above code only takes the screen shot of the screen above the on-screen keyboard and fails to take the screen shot of the on-screen keyboard.

 

So I am requesting your valuable feedback on how I can get screen shot of the full screen, including the on-screen keyboard when it is visible.

 

Thanks and Regards

Dipta P

Developer
Posts: 147
Registered: ‎08-27-2010
My Device: 9800
My Carrier: airtel

Re: Capturing Screenshot using touch screen devices

[ Edited ]

I think when the on-screen keyboard is visible

Display.getHeight() will return actual height - height of virtual keyboard.

 

so for that don't evaluate Display.getHeight() every time.

 

 

Edit: i have tested on storm 

 

when on- screen keyboard is not there height is 480

and when on- screen keyboard is there height is 248

Highlighted
Developer
Posts: 216
Registered: ‎02-18-2010
My Device: 9350,8520
My Carrier: no

Re: Capturing Screenshot using touch screen devices

You can store the value of Display.getHeight() in a static variable before getting the keyboard on the screen. i.e. 

 

static int temp=Display.getHeight(); 

 

after that initialize the Bitmap with,

 

Bitmap screenBitmap=new Bitmap(Display.getWidth(),temp);
Contributor
Posts: 11
Registered: ‎12-10-2010
My Device: Not Specified

Re: Capturing Screenshot using touch screen devices

Hello Vivart and Aman, thanks to both of you for your feedback. I will try the solution you provided and will let you know the result.

Contributor
Posts: 11
Registered: ‎12-10-2010
My Device: Not Specified

Re: Capturing Screenshot using touch screen devices

Based on your suggestion I changed the code so that height is retrieved only once when the on-screen keyboard is not visible, as mentioned by Vivart, the height is 480 in this case.

 

Now when the on-screen keyboard is visible if I pass the following code:

Bitmap screenBitmap=new Bitmap(Display.getWidth(),orginalHeight); Display.screenshot(screenBitmap);

 

the second line is throwing IllegalArgumentException. Here the originalHeight=480 which was retrieved when the on-screen keyboard was not visible.

 

The second line is only executing when I give Display.getHeight() while creating the Bitmap object but with this the on-screen keyboard is not captured as screen shot.

 

Need your valuable help and feedback on this.

Developer
Posts: 147
Registered: ‎08-27-2010
My Device: 9800
My Carrier: airtel

Re: Capturing Screenshot using touch screen devices

try this code

 

 

Bitmap screenBitmap=new Bitmap(Display.getWidth(),orginalHeight);
				Display.screenshot(screenBitmap,0,0,Display.getWidth(),orginalHeight);

 

 

Contributor
Posts: 11
Registered: ‎12-10-2010
My Device: Not Specified

Re: Capturing Screenshot using touch screen devices

Hello Vivart, Thanks a lot, the code you posted worked perfectly Smiley Happy

 

I never looked on that method.

 

Thanks a lot again