Android 获得View截屏最优方案

/** * 获得View的截屏 Bitmap * * @param view * @return */public static Bitmap getMagicDrawingCache(Context context,View view,boolean quick_cache) {         Bitmap bitmap = (Bitmap) view.getTag(R.id.cacheBitmapKey);    Boolean dirty = (Boolean) view.getTag(R.id.cacheBitmapDirtyKey);    if (view.getWidth() + view.getHeight() == 0) {             view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());    }    int viewWidth = view.getWidth();    int viewHeight = view.getHeight();    if (bitmap == null || bitmap.getWidth() != viewWidth || bitmap.getHeight() != viewHeight) {             if (bitmap != null && !bitmap.isRecycled()) {                 bitmap.recycle();        }        bitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);        view.setTag(R.id.cacheBitmapKey, bitmap);        dirty = true;    }    if (dirty == true || !quick_cache) {             bitmap.eraseColor(context.getResources().getColor(android.R.color.transparent));        Canvas canvas = new Canvas(bitmap);        view.draw(canvas);        view.setTag(R.id.cacheBitmapDirtyKey, false);    }    return bitmap;}

xml资源需要添加id

<item type="id" name="cacheBitmapKey"/>    <item type="id" name="cacheBitmapDirtyKey"/>

更多相关文章

  1. Caused by: org.gradle.api.internal.plugins.PluginApplication
  2. android 瀑布流
  3. 腾讯代理下载Android(安卓)SDK
  4. android 获取 imei号码以及其他信息
  5. android获得屏幕高度和宽度
  6. android设备添加F1-F12按键功能
  7. android 图表引擎
  8. Android(安卓)获取View高度宽度
  9. webView去掉右侧导航条

随机推荐

  1. Android学习之路六:ProgressBar
  2. android读取功能
  3. android manifest.xml中元素含义
  4. android琐碎日记七
  5. Android:LayoutAnimation、布局动画
  6. android 自定义字体
  7. Android通过串口与PC通信
  8. Android应用程序的安装位置
  9. 非UI线程可不可以更新UI(一)
  10. android GridView 去掉自带点击边框效果