项目要求把统计图截屏分享,但是统计图有5个,上层为scrollview,在网上查询了并找到了解决方法:
-
-
-
-
public static Bitmap getBitmapByView(ScrollView scrollView) {
-
int h = 0;
-
Bitmap bitmap = null;
-
-
for (int i = 0; i < scrollView.getChildCount(); i++) {
-
h += scrollView.getChildAt(i).getHeight();
-
scrollView.getChildAt(i).setBackgroundResource(R.drawable.bg3);
-
}
-
Log.d(TAG, "实际高度:" + h);
-
Log.d(TAG, " 高度:" + scrollView.getHeight());
-
-
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
-
Bitmap.Config.ARGB_8888);
-
final Canvas canvas = new Canvas(bitmap);
-
scrollView.draw(canvas);
-
-
FileOutputStream out = null;
-
try {
-
out = new FileOutputStream("/sdcard/screen_test.png");
-
} catch (FileNotFoundException e) {
-
e.printStackTrace();
-
}
-
try {
-
if (null != out) {
-
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
-
out.flush();
-
out.close();
-
}
-
} catch (IOException e) {
-
-
}
-
return bitmap;
-
}
android 开发之ScrollView 截屏代码,布布扣,bubuko.com
android 开发之ScrollView 截屏代码
原文:http://blog.csdn.net/webgeek/article/details/21400141