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

Capture and save a screen shot

by BlackBerry Development Advisor ‎02-16-2010 03:15 PM - edited ‎09-16-2010 02:38 PM (9,111 Views)

Summary

 

This article applies to the following:

  • BlackBerry® Device Software 4.3 and later
  • BlackBerry smartphones

Details

 

The following code sample demonstrates how to capture and save a screen shot within a BlackBerry smartphone application.

 

Note: The sample code should be executed in its own thread because it performs IO operations.

 

A complete sample application can be downloaded here.

 

 

//Get the dimensions of the screen.
int width = Display.getWidth();
int height = Display.getHeight();

//Create a bitmap to store the screen capture in.
Bitmap bm = new Bitmap(width, height);
Display.screenshot(bm);

//Convert the Bitmap object to a PNG.
PNGEncodedImage png = PNGEncodedImage.encode(bm);

//Save the PNG to the micro SD card.
FileConnection fc = (FileConnection)Connector.open("file:///SDCard/screenCap.png");

//This sample overwrites the file. Delete the file if it exists.
if (fc.exists())
{
fc.delete();
}

//Create the file.
fc.create();

//Write out the data to the file.
DataOutputStream out = fc.openDataOutputStream();

out.write(png.getData());

//Close the Connections.
out.close();
fc.close();

 

Contributors
Comments
by New Developer on ‎09-12-2010 01:31 PM

Doesn´t  matter if you take the Screenshoot in its own thread, there is an issue with the screenshoots in the OS 4.5 into any folder, some times the Icons disappear and the menu too.   I thought that was my code but I could test with the sample code below here and the problem persist.

The only solution that I can find was take 3 or more screenshoot and compare its lenghts. The bigger one it´s the screenshoot with less issues.

Users Online
Currently online: 17 members 840 guests
Please welcome our newest community members: