android截图 - 截取ContentView - 截取指定的View并且保存
2013-04-17 18:14
513 查看
截取DecorView
截取指定的View
截取不包括状态栏的部分
getWindow().getDecorView().setDrawingCacheEnabled(true); try { File myCaptureFile = new File("/mnt/sdcard/" + System.currentTimeMillis() + ".jpg"); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(myCaptureFile)); getWindow().getDecorView().getDrawingCache() .compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); } getWindow().getDecorView().setDrawingCacheEnabled(false);
截取指定的View
view.setDrawingCacheEnabled(true); try { File myCaptureFile = new File("/mnt/sdcard/" + System.currentTimeMillis() + ".jpg"); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(myCaptureFile)); view.getDrawingCache() .compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); } view().setDrawingCacheEnabled(false);
截取不包括状态栏的部分
/** * 页面返回动画 */ private void gobackAnimation(){ getWindow().getDecorView().setDrawingCacheEnabled(true); Bitmap bm = getWindow().getDecorView().getDrawingCache(); Rect rect = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); final Bitmap bitmap = Bitmap.createBitmap(bm, 0, rect.top, Device.getScreenWidth(), Device.getScreenHeight() - rect.top);; bm.recycle(); final ImageView imageView = new ImageView(ActivityOnlineAndUser.this); imageView.setScaleType(ScaleType.FIT_XY); imageView.setImageBitmap(bitmap); getWindow().addContentView(imageView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)); Animation anim = AnimationUtils.loadAnimation(ActivityOnlineAndUser.this, R.anim.push_right_out); anim.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { // 回收资源 imageView.setImageBitmap(null); bitmap.recycle(); ((ViewGroup)imageView.getParent()).removeView(imageView); // 设置成False,否则会很浪费性能 getWindow().getDecorView().setDrawingCacheEnabled(false); } }); imageView.startAnimation(anim); }
相关文章推荐
- Android使用ContentObserver监听数据库变化 接受指定号码的短信,并且不让系统截取到通知用户
- Android使用ContentObserver监听数据库变化 接受指定号码的短信,并且不让系统截取到通知用户
- android对View控件截图并保存
- Android中实现截图保存到指定目录或者系统图片,并支持批量删除
- [Android] 拍照、截图、保存并显示在ImageView控件中
- android 通过uri截取指定大小的图片显示在imageview上
- Android 截取指定号码的短信,并且不让系统获取短信通知用户
- Android仿银行客户签名并且保存签名的截图文件并命名为本地时间
- Android 截取指定号码的短信 并且不让系统获取短信通知用户
- Android中调用系统摄像并且保存到指定位置的一些问题&Uri转文件路径方法
- 初学者---Android全屏截图的方法,返回Bitmap并且保存在SD卡上
- Android中让TextView显示指定的行数并且多出的部分显示省略号
- android拍照,截图,保存并显示在ImageView控件中
- Android保存截图到系统图库和指定的文件夹
- android仿银行客户签名并且保存签名的截图文件,文件名为本地时间
- Android全屏截图的方法,返回Bitmap并且保存在SD卡上
- Android全屏截图的方法,返回Bitmap并且保存在SD卡上
- android代码截屏截切图片并且保存到指定文件夹中
- Android中如何让TextView显示指定的行数并且多出的部分显示省略号
- Android中将布局文件/View添加至窗口过程分析 ---- 从setContentView()谈起