http://www.yee4.com/blog/851.html
android中实现屏幕截图的代码
作者: 七彩天空 分类: android开发技巧 发布时间: 2015-03-13 10:54 没有评论android中实现屏幕截图思路
android开发中实现屏幕截图,也就是将view转换成对应的bitmap,然后把bitmap保存为本地图片。将view转换成对应的bitmap有两种方式:1.调用view.draw方法,将view转换成对应的bitmap。2.调用view.getDrawingCache方法,获取view对应的bitmap。
android中实现屏幕截图方法一:view.draw
public static Bitmap convertViewToBitmap(View view, int bitmapWidth, int bitmapHeight){Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
view.draw(new Canvas(bitmap));
return bitmap;
}
android中实现屏幕截图方法二:view.getDrawingCache
public static Bitmap convertViewToBitmap(View view){
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
return bitmap;
}