user1059747
user1059747

Reputation: 33

Take Screenshot of whole screen

I have seen a lot of code snippets for taking a screenshot but was not able to get something which takes the screenshot of the whole screen and not just a view. It should replicate the way we get screenshot using ddms.

Can someone help?

Upvotes: 3

Views: 5165

Answers (3)

Krishnabhadra
Krishnabhadra

Reputation: 34296

There is an Android Screenshot library, which is available here. There wiki pages says library can be used to take screenshot of entire screen without the need of root level access, even from an unsigned application. I have never tried it though. You can use it as a starting point.

Upvotes: 3

user3530722
user3530722

Reputation: 21

        sh = Runtime.getRuntime().exec("su", null, null);
        System.out.println("capturing");
        OutputStream outputstream = sh.getOutputStream();
        outputstream.write("/system/bin/screencap -p /sdcard/tos_processing.png".getBytes("ASCII"));
        outputstream.flush();
        outputstream.close();
        sh.waitFor();
        System.out.println("captured");
        bitmap = BitmapFactory.decodeFile("/sdcard/tos_processing.png");

Upvotes: 2

ashuu Smiley
ashuu Smiley

Reputation: 17

Try this it worked for me...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        view = (ImageView) findViewById(R.id.ImageView01);
        Button myBtn = (Button) findViewById(R.id.Button01);
        myBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                View v1 = view.getRootView();

                v1.setDrawingCacheEnabled(true);

                Bitmap bm = v1.getDrawingCache();
                BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);

                ImageView view2 = (ImageView) findViewById(R.id.ImageView01);

                view2.setBackgroundDrawable(bitmapDrawable);
            }
        });
}

Upvotes: 0

Related Questions