上代码:
public class MainActivity extends Activity {
ImageView imgView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView) findViewById(R.id.imageView);
imgView.setDrawingCacheEnabled(true);
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
imgView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imgView.layout(0, 0, imgView.getMeasuredWidth(), imgView.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(imgView.getDrawingCache());
imgView.setDrawingCacheEnabled(false);
String strPath ="/testSaveView/"+UUID.randomUUID().toString()+".png";
if (Environment.g