Jump to content
Android Forum - A Community For Android Users and Enthusiasts

How to use the image of a screenshot?


Recommended Posts

I want to use the code below to take screenshots of my application. But I want the picture which is produced to use it to change my background, like this Layout.setBackgroundResource(resid). How I can do this? Where I will find the image's path to use it to change Background? In Activity I call the takeScreenShot.  


private static Bitmap takeScreenShot(Activity activity)
    View view = activity.getWindow().getDecorView();
    Bitmap b1 = view.getDrawingCache();
    Rect frame = new Rect();
    int statusBarHeight = frame.top;
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

    Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height  - statusBarHeight);
    return b;
private static void savePic(Bitmap b, String strFileName)
    FileOutputStream fos = null;
        fos = new FileOutputStream(strFileName);
        if (null != fos)
            b.compress(Bitmap.CompressFormat.PNG, 90, fos);
    catch (FileNotFoundException e)
    catch (IOException e)



Link to comment
Share on other sites

you can try this code


here is the main java file


package pack.coderzheaven;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class ScreenShotDemo extends Activity {
    LinearLayout L1;
    ImageView image;
    public void onCreate(Bundle savedInstanceState) {
        L1 = (LinearLayout) findViewById(R.id.LinearLayout01);
        Button but = (Button) findViewById(R.id.Button01);
        but.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                View v1 = L1.getRootView();
                Bitmap bm = v1.getDrawingCache();
                BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
                image = (ImageView) findViewById(R.id.ImageView01);

And this is the layout file main.xml



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...