700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > android 截图 listview Android屏幕及view的截图实例详解

android 截图 listview Android屏幕及view的截图实例详解

时间:2021-11-30 15:17:00

相关推荐

android 截图 listview Android屏幕及view的截图实例详解

Android屏幕及view的截图实例详解

屏幕可见区域的截图

整个屏幕截图的话可以用View view = getWindow().getDecorView();

public static Bitmap getNormalViewScreenshot(View view) {

view.setDrawingCacheEnabled(true);

view.buildDrawingCache();

return view.getDrawingCache();

}

scrollview的整体截屏

public static Bitmap getWholeScrollViewToBitmap(View view) {

view.measure(MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED),MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED));

view.layout(0,view.getMeasuredWidth(),view.getMeasuredHeight());

view.buildDrawingCache();

Bitmap bitmap = view.getDrawingCache();

return bitmap;

}

webview的整体截图

public static Bitmap getWholeWebViewToBitmap(WebView webView) {

Picture snapShot = webView.capturePicture();

Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(),snapShot.getHeight(),Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(bmp);

snapShot.draw(canvas);

return bmp;

}

listview的整体截图

public static Bitmap getWholeListViewItemsToBitmap(ListView listview) {

ListAdapter adapter = listview.getAdapter();

int itemscount = adapter.getCount();

int allitemsheight = 0;

List bmps = new ArrayList();

for (int i = 0; i < itemscount; i++) {

View childView = adapter.getView(i,null,listview);

childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(),MeasureSpec.EXACTLY),MeasureSpec.UNSPECIFIED));

childView.layout(0,childView.getMeasuredWidth(),childView.getMeasuredHeight());

childView.setDrawingCacheEnabled(true);

childView.buildDrawingCache();

bmps.add(childView.getDrawingCache());

allitemsheight += childView.getMeasuredHeight();

}

Bitmap bigbitmap = Bitmap.createBitmap(listview.getMeasuredWidth(),allitemsheight,Bitmap.Config.ARGB_8888);

Canvas bigcanvas = new Canvas(bigbitmap);

Paint paint = new Paint();

int iHeight = 0;

for (int i = 0; i < bmps.size(); i++) {

Bitmap bmp = bmps.get(i);

bigcanvas.drawBitmap(bmp,iHeight,paint);

iHeight += bmp.getHeight();

bmp.recycle();

bmp = null;

}

return bigbitmap;

}

需要多次截图的话,需要用到 view.destroyDrawingCache();

Bitmap normalViewScreenshot = ScreenShotUtils.getNormalViewScreenshot(mFrameContent);

if (normalViewScreenshot != null) {

Bitmap b = Bitmap.createBitmap(normalViewScreenshot);

mImageResult.setImageBitmap(b);

mFrameContent.destroyDrawingCache();

}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。