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
Developer
Posts: 79
Registered: ‎09-22-2010
My Device: 9700

taking ScreenShot Of Screen

i am trying to develop an application to take ScreenShot of Device, while Application is in backGround.

i use the code 

import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.PNGEncodedImage;

public  class CaptureThread extends Thread 
{

	public CaptureThread()
	{
	}
	public void run()
	{
		FileConnection fc = null;
		DataOutputStream out = null;
		try
		{
			//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);
			System.out.println("Png Convertd"+png);
			//Save the PNG to the micro SD card.
			fc = (FileConnection)Connector.open("file:///SDCard/screenCap10.png");
			//This sample overwrites the file.  Delete the file if it exists.
			if (fc.exists())
			{
				fc.delete();
			}
			//Create the file.
			fc.create();
			System.out.println("Created At file:///SDCard/screenCap.png");
			//Write out the data to the file.
			out = fc.openDataOutputStream();
			out.write(png.getData());
		}
		catch (Exception ex)
		{
			System.out.println("Exception: " + ex.toString());
		}
		finally 
		{
			//Close the connections.
			 if (out != null) 
			 {
			     try 
			     { 
			        out.close();
			        System.out.println("Job Done");
			     } 
			     catch (IOException e){}
			}
			   
			if (fc != null) 
			{
			    try 
			    { 
			        fc.close();
			    } 
			    catch (IOException e){} 
			}
		}
	}
}

 and Application class

 

public class ScreenShotApp extends UiApplication
{
	static CaptureThread ct =null;
	public static void main(String[] args)
	{
		UiApplication theApp = new ScreenShotApp();
		theApp.enterEventDispatcher();
	}
	public ScreenShotApp()
	{
		MainScreen mainScreen = new MainScreen();
		MenuItem menu = new MenuItem("Take screenshot", 40, 40)
		{
			public void run()
			{
				System.out.println("Menu option selected");
				Status.show("Taking screen capture", 2000);
				CaptureThread ct = new CaptureThread();
				ct.start();
			}
		};
	    mainScreen.addMenuItem(menu);
		mainScreen.add(new LabelField("Use the menu to capture a screenshot."));
		System.out.println("constructor Calling Finished");
		pushScreen(mainScreen);
	}
}

 

 i just need  to grab whatever on Screen except the My own Apps Screen. Above Code is Giving me A Blank white png.

which is of MainScreen of this app.

can i get ScreenShot when this App is in background.? and How it possible?

 

 

Contributor
Posts: 44
Registered: ‎10-28-2010
My Device: Not Specified

Re: taking ScreenShot Of Screen

did you try to work with
JPEGEncodedImage png = JPEGEncodedImage.encode(screenShot, 100);
Highlighted
Developer
Posts: 79
Registered: ‎09-22-2010
My Device: 9700

Re: taking ScreenShot Of Screen

thanks for Reply, But my Goal is to build Application Which is Run in BackGround and take ScreenShot of Screen by Any of spefic Key ,

Any idea plz.

i want to run Application in BackGround.

Thanks in Advance

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: taking ScreenShot Of Screen

you cannot monitor keys (except some few) in a background app, only the active application receives the key events.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter