android截屏

来源:互联网 发布:jsp与php的区别 编辑:程序博客网 时间:2024/04/30 12:20


public void onShow(View v) {




SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd_HH-mm-ss",
Locale.US);
String fname = Environment.getExternalStorageDirectory() + "/test_"
+ sdf.format(new Date()) + ".png";
FileOutputStream out = null;
View view = v.getRootView();
view.invalidate();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();




//ImageView iv=(ImageView) findViewById(R.id.ivShow);
//iv.setImageBitmap(bitmap);
if(bitmap != null){
Log.e("tag","bitmap got!");
try{
out = new FileOutputStream(fname);
bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
}catch(Exception
e) {
e.printStackTrace();
}




try {
FileInputStream fis = new FileInputStream(fname);
bitmap = BitmapFactory.decodeStream(fis);
setShareContent(bitmap);
umController.openShare((Activity)context, false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}else{
Toast.makeText(context, "分享失败", 5000).show();
Log.e("tag","bitmap is NULL!");
}
}





说明:地图截屏需要实现地图的监听方法。
0 0