展会信息港展会大全

android 开发之ScrollView 截屏代码
来源:互联网   发布日期:2015-10-03 10:53:31   浏览:836次  

导读:项目要求把统计图截屏分享,但是统计图有5个,上层为scrollview,在网上查询了并找到了解决方法:[java]/*** 截取scrollview的屏幕* **/public...

项目要求把统计图截屏分享,但是统计图有5个,上层为scrollview,在网上查询了并找到了解决方法:

[java]

/**

* 截取scrollview的屏幕

* **/

public static Bitmap getBitmapByView(ScrollView scrollView) {

int h = 0;

Bitmap bitmap = null;

// 获取listView实际高度

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 = 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) {

// TODO: handle exception

}

return bitmap;

}

赞助本站

人工智能实验室

相关热词: android开发

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港