public BlurTask(View target, BlurFactor factor, Callback callback) { this.res = target.getResources(); this.factor = factor; this.callback = callback; this.contextWeakRef = new WeakReference<>(target.getContext()); target.setDrawingCacheEnabled(true); target.destroyDrawingCache(); target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); bitmap = target.getDrawingCache(); }
/** * Returns a bitmap of a given View. * * @param view the view to save a bitmap from * @return a bitmap of the given view * */ private Bitmap getBitmapOfView(final View view){ view.destroyDrawingCache(); view.buildDrawingCache(false); Bitmap orig = view.getDrawingCache(); Bitmap.Config config = null; if(orig == null) { return null; } config = orig.getConfig(); if(config == null) { config = Bitmap.Config.ARGB_8888; } Bitmap b = orig.copy(config, false); orig.recycle(); view.destroyDrawingCache(); return b; }
private static Bitmap takeScreenShot(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b; }
/**销毁并回收内存,建议在对应的View占用大量内存时使用 * @warn 只能在UI线程中调用 */ public void onDestroy() { if (itemView != null) { try { itemView.destroyDrawingCache(); } catch (Exception e) { Log.w(TAG, "onDestroy try { itemView.destroyDrawingCache();" + " >> } catch (Exception e) {\n" + e.getMessage()); } } onDataChangedListener = null; data = null; position = 0; }
public static Bitmap of(View view, BlurFactor factor) { view.setDrawingCacheEnabled(true); view.destroyDrawingCache(); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); Bitmap cache = view.getDrawingCache(); Bitmap bitmap = of(view.getContext(), cache, factor); cache.recycle(); return bitmap; }
/**销毁并回收内存,建议在对应的View占用大量内存时使用 * @warn 只能在UI线程中调用 */ public void onDestroy() { if (convertView != null) { try { convertView.destroyDrawingCache(); } catch (Exception e) { Log.w(TAG, "onDestroy try { convertView.destroyDrawingCache();" + " >> } catch (Exception e) {\n" + e.getMessage()); } convertView = null; } onDataChangedListener = null; onTouchListener = null; onClickListener = null; onLongClickListener = null; onClickViewList = null; data = null; position = 0; context = null; }
view.destroyDrawingCache(); return b;
/** * 添加需要移动的 镜像View */ private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view) { /** * 我们要获取cache首先要通过setDrawingCacheEnable方法开启cache,然后再调用getDrawingCache方法就可以获得view的cache图片了。 buildDrawingCache方法可以不用调用,因为调用getDrawingCache方法时,若果cache没有建立,系统会自动调用buildDrawingCache方法生成cache。 若想更新cache, 必须要调用destoryDrawingCache方法把旧的cache销毁,才能建立新的。 当调用setDrawingCacheEnabled方法设置为false, 系统也会自动把原来的cache销毁。 */ view.destroyDrawingCache(); view.setDrawingCacheEnabled(true); final ImageView mirrorView = new ImageView(recyclerView.getContext()); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); mirrorView.setImageBitmap(bitmap); view.setDrawingCacheEnabled(false); int[] locations = new int[2]; view.getLocationOnScreen(locations); int[] parenLocations = new int[2]; recyclerView.getLocationOnScreen(parenLocations); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(bitmap.getWidth(), bitmap.getHeight()); params.setMargins(locations[0], locations[1] - parenLocations[1], 0, 0); parent.addView(mirrorView, params); return mirrorView; }
Bitmap cacheBmp = view.getDrawingCache(); Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true); view.destroyDrawingCache(); return new BitmapDrawable(viewBmp);
/** * 获取当前屏幕截图,包含状态栏(这个方法没测试通过) * * @param activity * @return Bitmap */ public static Bitmap snapShotWithStatusBar(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bmp = view.getDrawingCache(); int width = getScreenWidth(activity); int height = getScreenHeight(activity); Bitmap bp = null; bp = Bitmap.createBitmap(bmp, 0, 0, width, height); view.destroyDrawingCache(); return bp; }
/** * 获取当前屏幕截图,不包含状态栏(这个方法没测试通过) * * @param activity * @return Bitmap */ public static Bitmap snapShotWithoutStatusBar(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bmp = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = getScreenWidth(activity); int height = getScreenHeight(activity); Bitmap bp = null; bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return bp; } }
private Bitmap getBitmap(View view) { view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(), 0, 0, UIUtil.getRealScreenWidth(mActivity), UIUtil.getRealScreenHeight(mActivity) - UIUtil.getNavigationBarHeight(mActivity)); view.destroyDrawingCache(); return bitmap; }
Bitmap cacheBmp = view.getDrawingCache(); Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true); view.destroyDrawingCache(); return new BitmapDrawable(viewBmp);
if (view != null) { try { view.destroyDrawingCache(); } catch (Exception e) { Log.w(TAG, "onDestroy try { view.destroyDrawingCache();" +
if (view != null) { try { view.destroyDrawingCache(); } catch (Exception e) { Log.w(TAG, "onDestroy try { view.destroyDrawingCache();" +
private static void refreshView(View view, ExtraRefreshable extraRefreshable) { if (view == null) return; view.destroyDrawingCache(); if (view instanceof Tintable) { ((Tintable) view).tint();
view.destroyDrawingCache(); view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color);
view.destroyDrawingCache(); view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color);
if (view != null) { try { view.destroyDrawingCache(); } catch (Exception e) { Log.w(TAG, "onDestroy try { view.destroyDrawingCache();" +
/**销毁并回收内存 * @warn 子类如果要使用这个方法内用到的变量,应重写onDestroy方法并在super.onDestroy();前操作 */ @Override protected void onDestroy() { Log.d(TAG, "\n onDestroy <<<<<<<<<<<<<<<<<<<<<<<"); dismissProgressDialog(); BaseBroadcastReceiver.unregister(context, receiver); ThreadManager.getInstance().destroyThread(threadNameList); if (view != null) { try { view.destroyDrawingCache(); } catch (Exception e) { Log.w(TAG, "onDestroy try { view.destroyDrawingCache();" + " >> } catch (Exception e) {\n" + e.getMessage()); } } isAlive = false; isRunning = false; super.onDestroy(); inflater = null; view = null; tvBaseTitle = null; fragmentManager = null; progressDialog = null; threadNameList = null; intent = null; context = null; Log.d(TAG, "onDestroy >>>>>>>>>>>>>>>>>>>>>>>>\n"); }