android.view.View#destroyDrawingCache ( )源码实例Demo

下面列出了android.view.View#destroyDrawingCache ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: letv   文件: ChannelFragmentAdapter.java
private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view) {
    view.destroyDrawingCache();
    view.setDrawingCacheEnabled(true);
    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);
    LayoutParams params = new LayoutParams(bitmap.getWidth(), bitmap.getHeight());
    params.setMargins(locations[0], (locations[1] - parenLocations[1]) + UIsUtils.dipToPx(44.0f), 0, 0);
    parent.addView(mirrorView, params);
    return mirrorView;
}
 
源代码2 项目: XKnife-Android   文件: ScreenUtils.java
/**
 * Snap shot without status bar bitmap.
 *
 * @param activity the activity
 * @return bitmap 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;

}
 
源代码3 项目: Android_UE   文件: ScreenUtils.java
/**
 * 获取当前屏幕截图,不包含状态栏
 *
 * @param activity
 * @return
 */
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;

}
 
源代码4 项目: youqu_master   文件: DisplayUtil.java
/**
 * 获取当前屏幕截图,不包含状态栏(这个方法没测试通过)
 * 
 * @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;
}
 
源代码5 项目: SweetTips   文件: ScreenUtil.java
/**
 * 获取当前屏幕截图,不包含状态栏
 * @param activity
 * @return bp
 */
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    if (bmp == null) {
        return null;
    }
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    Bitmap bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, bmp.getWidth(), bmp.getHeight() - statusBarHeight);
    view.destroyDrawingCache();
    view.setDrawingCacheEnabled(false);

    return bp;
}
 
源代码6 项目: LLApp   文件: ScreenUtils.java
/**
 * 获取当前屏幕截图,不包含状态栏
 *
 * @param activity
 * @return
 */
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();
    int height = getScreenHeight();
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
            - statusBarHeight);
    view.destroyDrawingCache();
    return bp;

}
 
源代码7 项目: GearLoadingProject   文件: FastBlur.java
private Bitmap prepareAndSetBitmap(final View targetView) {
        targetView.setDrawingCacheEnabled(true);
        targetView.destroyDrawingCache();
        targetView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO);
        targetView.buildDrawingCache(true);
        Bitmap sourceBitmap = Bitmap.createBitmap(targetView.getDrawingCache());
        targetView.setDrawingCacheEnabled(false);
        targetView.destroyDrawingCache();

        Bitmap overlay = Bitmap.createBitmap((int) (targetView.getMeasuredWidth() / scaleFactor),
                (int) (targetView.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(overlay);
//        canvas.translate(-targetView.getLeft() / scaleFactor, -targetView.getTop() / scaleFactor);
        canvas.scale(1 / scaleFactor, 1 / scaleFactor);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        canvas.drawBitmap(sourceBitmap, 0, 0, paint);
//        canvas.drawColor(Color.RED);
        sourceBitmap.recycle();
        return FastBlur.doBlur(overlay, radius, false);
    }
 
源代码8 项目: Noyze   文件: Utils.java
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;
}
 
源代码9 项目: RemoteControlView   文件: MyDragShadowBuilder.java
public MyDragShadowBuilder(View v) {
    // 保存传给myDragShadowBuilder的View参数
    super(v);
    // 将view转为Drawable
    v.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache(true));
    shadow = new BitmapDrawable(null, bitmap);
    v.destroyDrawingCache();
    v.setDrawingCacheEnabled(false);
}
 
源代码10 项目: timecat   文件: DragDropHelper.java
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;
}
 
源代码11 项目: MousePaint   文件: ScreenUtil.java
/**
 * 获取当前屏幕截图,包含状态栏
 * @param activity
 * @return
 */
public static Bitmap snapShotWithStatusBar(Activity activity)
{
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int width = getScreenWidth();
    int height = getScreenHeight();
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
    view.destroyDrawingCache();
    return bp;

}
 
源代码12 项目: xDrip-plus   文件: BgSparklineBuilder.java
/**
 * 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;
}
 
源代码13 项目: TitleLayout   文件: ScreenUtil.java
/**
 * 获取当前屏幕截图,不包含状态栏
 *
 * @param activity activity
 * @return Bitmap
 */
public static Bitmap captureWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int statusBarHeight = getStatusBarHeight(activity);//获取状态栏高度
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    Bitmap ret = Bitmap.createBitmap(bmp, 0, statusBarHeight, dm.widthPixels, dm.heightPixels - statusBarHeight);
    view.destroyDrawingCache();
    return ret;
}
 
源代码14 项目: MultiItem   文件: DragFloatViewHelper.java
/**
 * @param coverView 被覆盖的view,用于生产浮层View
 * @return 需要跟随手势浮动的 View
 */
protected View createFloatView(View coverView) {
    ImageView floatView = new ImageView(coverView.getContext());
    coverView.destroyDrawingCache();
    coverView.setDrawingCacheEnabled(true);
    Bitmap bitmap = coverView.getDrawingCache();
    if (bitmap != null && !bitmap.isRecycled()) {
        floatView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        floatView.setImageBitmap(bitmap);
    }
    return floatView;
}
 
源代码15 项目: styT   文件: WidgetUtils.java
/**
 * 获取当前屏幕截图,包含状态栏
 *
 * @param activity
 * @return
 */
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;

}
 
源代码16 项目: Blurry   文件: Blur.java
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;
}
 
源代码17 项目: AndroidStudyDemo   文件: BitmapUtil.java
/**
 * 把一个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;
}
 
源代码18 项目: react-native-baidu-map   文件: BitmapUtil.java
public static BitmapDescriptor createBitmapDescriptor(View view, int width, int height) {
    if (width > 0 && height > 0) {
        view.layout(0, 0, width, height);
    } else if (view.getMeasuredWidth() == 0 || view.getMeasuredHeight() == 0) {
        view.layout(0, 0, view.getMeasuredWidth() > 0 ? view.getMeasuredWidth() : 50, view.getMeasuredHeight() > 0 ? view.getMeasuredHeight() : 100);
    }
    view.buildDrawingCache();
    BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(view.getDrawingCache());
    view.destroyDrawingCache();
    return bitmapDescriptor;
}
 
源代码19 项目: xDrip-Experimental   文件: BgSparklineBuilder.java
/**
 * 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;
}
 
源代码20 项目: AndroidDownload   文件: ConvertUtils.java
/**
 * 把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;
}
 
 方法所在类
 同类方法