List of usage examples for android.view View willNotCacheDrawing
@ViewDebug.ExportedProperty(category = "drawing") @Deprecated public boolean willNotCacheDrawing()
From source file:Main.java
public static Bitmap convertViewToBitmap(View comBitmap, int width, int height) { Bitmap bitmap = null;//from w w w .j a v a2s. c o m if (comBitmap != null) { comBitmap.clearFocus(); comBitmap.setPressed(false); boolean willNotCache = comBitmap.willNotCacheDrawing(); comBitmap.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = comBitmap.getDrawingCacheBackgroundColor(); comBitmap.setDrawingCacheBackgroundColor(0); float alpha = comBitmap.getAlpha(); comBitmap.setAlpha(1.0f); if (color != 0) { comBitmap.destroyDrawingCache(); } int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY); comBitmap.measure(widthSpec, heightSpec); comBitmap.layout(0, 0, width, height); comBitmap.buildDrawingCache(); Bitmap cacheBitmap = comBitmap.getDrawingCache(); if (cacheBitmap == null) { Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")", new RuntimeException()); return null; } bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view comBitmap.setAlpha(alpha); comBitmap.destroyDrawingCache(); comBitmap.setWillNotCacheDrawing(willNotCache); comBitmap.setDrawingCacheBackgroundColor(color); } return bitmap; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * View??bitmap/*from w w w . j a va 2s .c o m*/ * * @param view * View * @return Bitmap */ public static Bitmap getBitmapFromView2(View view) { view.clearFocus(); view.setPressed(false); // false boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(0); if (color != 0) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { if (DEBUG) { Log.e(TAG, "failed getViewBitmap(" + view + ")", new RuntimeException()); } return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
/** * Draw the view into a bitmap.//w w w . j av a2 s . c o m */ public static Bitmap getViewBitmap(final View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); if (willNotCache || color != 0) { v.setWillNotCacheDrawing(false); v.setDrawingCacheBackgroundColor(0); v.destroyDrawingCache(); } boolean isDrawinCacheEnabled = v.isDrawingCacheEnabled(); Bitmap bitmap = null; try { v.setDrawingCacheEnabled(true); v.buildDrawingCache(true); bitmap = Bitmap.createBitmap(v.getDrawingCache(true)); } catch (Exception e) { bitmap = null; } v.setDrawingCacheEnabled(isDrawinCacheEnabled); // Restore the view if (willNotCache || color != 0) { v.destroyDrawingCache(); v.setDrawingCacheBackgroundColor(color); v.setWillNotCacheDrawing(willNotCache); } return bitmap; }
From source file:com.example.android_test.loopviewpager.LoopViewPager.java
Bitmap getViewBitmap(View v) { v.clearFocus();// ww w.ja v a 2 s.c om v.setPressed(false); // ?????????? boolean willNotCache = v.willNotCacheDrawing(); int color = v.getDrawingCacheBackgroundColor(); // ??????? v.setWillNotCacheDrawing(false); // ??????? v.setDrawingCacheBackgroundColor(0); // ???? if (color != 0) { v.destroyDrawingCache(); } // ?????? v.buildDrawingCache(); // ? Bitmap ? Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } // ? Bitmap ???????? Bitmap ? Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // ?????????? v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
From source file:org.chinenv.onroad.loopview.LoopViewPager.java
Bitmap getViewBitmap(View v) { v.clearFocus();/* w w w . j a v a 2s . c om*/ v.setPressed(false); // ?????????? boolean willNotCache = v.willNotCacheDrawing(); int color = v.getDrawingCacheBackgroundColor(); // ???????? v.setWillNotCacheDrawing(false); // ???????? v.setDrawingCacheBackgroundColor(0); // ????? if (color != 0) { v.destroyDrawingCache(); } // ?????? v.buildDrawingCache(); // ?Bitmap ?? Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } // ?Bitmap ???????? Bitmap ? Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // ?????????? v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java
Bitmap getViewBitmap(View v) { v.clearFocus();/*from w w w . ja v a 2s. c o m*/ v.setPressed(false); // ?????????? boolean willNotCache = v.willNotCacheDrawing(); int color = v.getDrawingCacheBackgroundColor(); // ??????? v.setWillNotCacheDrawing(false); // ??????? v.setDrawingCacheBackgroundColor(0); // ???? if (color != 0) { v.destroyDrawingCache(); } // ?????? v.buildDrawingCache(); // ? Bitmap ? Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { if (DEBUG) Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } // ? Bitmap ???????? Bitmap ? Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // ?????????? v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }