dimmisel Posted April 18, 2013 Share Posted April 18, 2013 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(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); 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); view.destroyDrawingCache(); return b; } private static void savePic(Bitmap b, String strFileName) { FileOutputStream fos = null; try { fos = new FileOutputStream(strFileName); if (null != fos) { b.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } Quote Link to comment Share on other sites More sharing options...
Neena Posted April 24, 2013 Share Posted April 24, 2013 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; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); L1 = (LinearLayout) findViewById(R.id.LinearLayout01); Button but = (Button) findViewById(R.id.Button01); but.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View v1 = L1.getRootView(); v1.setDrawingCacheEnabled(true); Bitmap bm = v1.getDrawingCache(); BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); image = (ImageView) findViewById(R.id.ImageView01); image.setBackgroundDrawable(bitmapDrawable); } }); } } And this is the layout file main.xml http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/LinearLayout01" > android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Take Screenshot" android:id="@+id/Button01" /> android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Take Screenshot" android:id="@+id/ImageView01" /> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.