Java Code Examples for android.view.View#getDrawingCacheBackgroundColor()
The following examples show how to use
android.view.View#getDrawingCacheBackgroundColor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BgSparklineBuilder.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(Color.TRANSPARENT); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { android.util.Log.e(TAG, "failed getViewBitmap(" + JoH.backTrace() + ")", new RuntimeException()); v.destroyDrawingCache(); // duplicate of below, flow could be reordered better v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 2
Source File: BgSparklineBuilder.java From NightWatch with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 3
Source File: BgSparklineBuilder.java From NightWatch with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 4
Source File: BgSparklineBuilder.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(Color.TRANSPARENT); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 5
Source File: ViewShot.java From zone-sdk with MIT License | 5 votes |
/** * @param view * @return * @deprecated use {@link #getCacheBitmap(View,Bitmap.Config)} * <br>感觉这个不好 会清除一些状态</br> * 仅仅为了得到的位图是RGB 565吧 * 但是 结果来看 大部分还是RGB8888 要和 View.mUse32BitDrawingCache相关 */ public static Bitmap getCacheBitmap_ConifgByWindow(View view) { // 将一个View转化成一张图片 view.clearFocus(); // 清除视图焦点 view.setPressed(false);// 将视图设为不可点击 boolean willNotCache = view.willNotCacheDrawing(); // 返回视图是否可以保存他的画图缓存 view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation //将视图在此操作时置为透明 int color = view.getDrawingCacheBackgroundColor(); // 获得绘制缓存位图的背景颜色 view.setDrawingCacheBackgroundColor(0); // 设置绘图背景颜色 if (color != 0) { // 如果获得的背景不是黑色的则释放以前的绘图缓存 view.destroyDrawingCache(); // 释放绘图资源所使用的缓存 } view.buildDrawingCache(); // 重新创建绘图缓存,此时的背景色是黑色 Bitmap cacheBitmap = view.getDrawingCache(); // 将绘图缓存得到的,注意这里得到的只是一个图像的引用 if (cacheBitmap == null) return failLog(view); Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // 将位图实例化 // Restore the view //恢复视图 view.destroyDrawingCache();// 释放位图内存 view.setWillNotCacheDrawing(willNotCache);// 返回以前缓存设置 view.setDrawingCacheBackgroundColor(color);// 返回以前的缓存颜色设置 return bitmap; }
Example 6
Source File: DragController.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); float alpha = v.getAlpha(); v.setAlpha(1.0f); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setAlpha(alpha); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 7
Source File: BitmapUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
/** * 把一个View的对象转换成bitmap * * @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) { Logger.e("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; }
Example 8
Source File: BgSparklineBuilder.java From NightWatch with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 9
Source File: Utils.java From Noyze with Apache License 2.0 | 5 votes |
public static Bitmap loadBitmapFromViewCache(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (null == cacheBitmap) return null; Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 10
Source File: BgSparklineBuilder.java From xDrip with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ protected Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(Color.TRANSPARENT); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { android.util.Log.e(TAG, "failed getViewBitmap(" + JoH.backTrace() + ")", new RuntimeException()); v.destroyDrawingCache(); // duplicate of below, flow could be reordered better v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 11
Source File: DragNDropListActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void onStartDrag(View itemView) { itemView.setVisibility(View.INVISIBLE); defaultBackgroundColor = itemView.getDrawingCacheBackgroundColor(); itemView.setBackgroundColor(backgroundColor); ImageView iv = (ImageView) itemView.findViewById(R.id.ImageView01); if (iv != null) iv.setVisibility(View.INVISIBLE); }
Example 12
Source File: XBitmapUtils.java From XFrame with Apache License 2.0 | 5 votes |
/** * 把一个View的对象转换成bitmap * * @param view View * @return Bitmap */ public static Bitmap getBitmapFromView2(View view) { if (view == null) { return null; } 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) { XPrintUtils.e( "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; }
Example 13
Source File: DragDropHelper.java From timecat with Apache License 2.0 | 5 votes |
private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 14
Source File: DragController.java From LB-Launcher with Apache License 2.0 | 5 votes |
/** * Draw the view into a bitmap. */ Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); float alpha = v.getAlpha(); v.setAlpha(1.0f); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setAlpha(alpha); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 15
Source File: ImageUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 通过 View Cache 绘制为 Bitmap * @param view {@link View} * @return {@link Bitmap} */ public static Bitmap getBitmapFromViewCache(final View view) { if (view == null) return null; try { // 清除视图焦点 view.clearFocus(); // 将视图设为不可点击 view.setPressed(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) return null; Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // 释放位图内存 view.destroyDrawingCache(); // 回滚以前的缓存设置、缓存颜色设置 view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getBitmapFromViewCache"); } return null; }
Example 16
Source File: Utils.java From Noyze with Apache License 2.0 | 5 votes |
public static Bitmap loadBitmapFromViewCache(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (null == cacheBitmap) return null; Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 17
Source File: BgSparklineBuilder.java From NightWatch with GNU General Public License v3.0 | 5 votes |
/** * Draw the view into a bitmap. */ private Bitmap getViewBitmap(View v) { v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap cacheBitmap = v.getDrawingCache(); if (cacheBitmap == null) { Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); return null; } Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 18
Source File: ConvertUtils.java From a with GNU General Public License v3.0 | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(); canvas.restore(); if (!bitmap.isRecycled()) { bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 19
Source File: ConvertUtils.java From AndroidDownload with Apache License 2.0 | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); if (!bitmap.isRecycled()) { LogUtils.verbose("recycle bitmap: " + bitmap.toString()); bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 20
Source File: ConvertUtils.java From AndroidPicker with MIT License | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(); canvas.restore(); if (!bitmap.isRecycled()) { LogUtils.verbose("recycle bitmap: " + bitmap.toString()); bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }