package com.cutScreen; import java.io.File; import java.io.FileOutputStream; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Main extends Activity { private static final String TAG = Main.class.getName(); private int count = 0; public static String SCREEN_SHOTS_LOCATION = "/mnt/sdcard/"; private Button button; //public ImageView iv; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setViews(); } public void setViews() { button = (Button) findViewById(R.id.button1); //iv = (ImageView) findViewById(R.id.imageView1); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub View taxi = Main.this.getWindow().getDecorView(); count++; try { takeScreenShot(taxi, SCREEN_SHOTS_LOCATION); } catch (Exception e) { // TODO Auto-generated catch block Log.e("tag", TAG); } } }); } public void takeScreenShot(View view) throws Exception { takeScreenShot(view, "default"); } public void takeScreenShot(View view, String name) throws Exception { view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b = view.getDrawingCache(); //iv.setImageBitmap(b); FileOutputStream fos = null; try { File sddir = new File(SCREEN_SHOTS_LOCATION); if (!sddir.exists()) { sddir.mkdirs(); } fos = new FileOutputStream(SCREEN_SHOTS_LOCATION + "taxicard"+String.valueOf(count) + ".png"); if (fos != null) { b.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } } catch (Exception e) { Log.e("tag", TAG); } } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/aaa"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout>