Java Code Examples for android.view.View#setDrawingCacheQuality()

The following examples show how to use android.view.View#setDrawingCacheQuality() . These examples are extracted from open source projects. 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 Project: YCWebView   File: AppUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 填充布局内容
 */
private static  Bitmap layoutView(final View viewBitmap, int width, int height) {
    // 整个View的大小 参数是左上角 和右下角的坐标
    viewBitmap.layout(0, 0, width, height);
    int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED);
    viewBitmap.measure(measuredWidth, measuredHeight);
    viewBitmap.layout(0, 0, viewBitmap.getMeasuredWidth(), viewBitmap.getMeasuredHeight());
    viewBitmap.setDrawingCacheEnabled(true);
    viewBitmap.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    viewBitmap.setDrawingCacheBackgroundColor(Color.WHITE);
    // 把一个View转换成图片
    Bitmap cachebmp = viewConversionBitmap(viewBitmap);
    viewBitmap.destroyDrawingCache();
    return cachebmp;
}
 
Example 2
Source Project: YCWebView   File: X5WebUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 填充布局内容
 * @param viewBitmap            view
 * @param width                 宽
 * @param height                高
 * @return
 */
private static  Bitmap layoutView(final View viewBitmap, int width, int height) {
    // 整个View的大小 参数是左上角 和右下角的坐标
    viewBitmap.layout(0, 0, width, height);
    //宽,父容器已经检测出view所需的精确大小,这时候view的最终大小SpecSize所指定的值,相当于match_parent或指定具体数值。
    int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    //高,表示父容器不对View有任何限制,一般用于系统内部,表示一种测量状态;
    int measuredHeight = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.UNSPECIFIED);
    viewBitmap.measure(measuredWidth, measuredHeight);
    viewBitmap.layout(0, 0, viewBitmap.getMeasuredWidth(), viewBitmap.getMeasuredHeight());
    viewBitmap.setDrawingCacheEnabled(true);
    viewBitmap.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    viewBitmap.setDrawingCacheBackgroundColor(Color.WHITE);
    // 把一个View转换成图片
    Bitmap cachebmp = viewConversionBitmap(viewBitmap);
    viewBitmap.destroyDrawingCache();
    return cachebmp;
}
 
Example 3
public Bitmap createBitmap(final Context context, RemoteViews remoteViews, boolean isBig, boolean systemId) {
	View mCache = null;
	try {
		mCache = createView(context, remoteViews, isBig, systemId);
	} catch (Throwable throwable) {
		try {
			// apply失败后,根据布局id创建view
			mCache = LayoutInflater.from(context).inflate(remoteViews.getLayoutId(), null);
		} catch (Throwable e) {

		}
	}
	if (mCache == null) {
		return null;
	}
	mCache.setDrawingCacheEnabled(true);
	mCache.buildDrawingCache();
	mCache.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
	return mCache.getDrawingCache();
}
 
Example 4
Source Project: GearLoadingProject   File: FastBlur.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example 5
Source Project: TLint   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private Drawable buildCounterDrawable(int count, int backgroundImageId) {
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.notification_count_layout, null);
    view.setBackgroundResource(backgroundImageId);
    TextView tvCount = (TextView) view.findViewById(R.id.tvCount);
    if (count == 0) {
        tvCount.setVisibility(View.GONE);
    } else {
        tvCount.setVisibility(View.VISIBLE);
        tvCount.setText(String.valueOf(count));
    }

    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

    view.setDrawingCacheEnabled(true);
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);

    return new BitmapDrawable(getResources(), bitmap);
}
 
Example 6
Source Project: Android-Commons   File: UI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generates a screenshot of the specified `View`
 *
 * @param view the `View` component
 * @return the screenshot
 */
public static Bitmap getViewScreenshot(final View view) {
	// set up the drawing cache
	view.setDrawingCacheEnabled(true);
	view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

	// get the screenshot
	final Bitmap viewScreenshot = view.getDrawingCache(true);
	final Bitmap output = viewScreenshot.copy(viewScreenshot.getConfig(), false);

	// disable the drawing cache again
	view.destroyDrawingCache();
	view.setDrawingCacheEnabled(false);

	return output;
}
 
Example 7
Source Project: YImagePicker   File: PBitmapUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return view的截图,在InVisible时也可以获取到bitmap
 */
public static Bitmap getViewBitmap(View view) {
    view.measure(View.MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), View.MeasureSpec.EXACTLY));
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache(true);
    return view.getDrawingCache(true);
}
 
Example 8
Source Project: YImagePicker   File: PBitmapUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return view的截图,在InVisible时也可以获取到bitmap
 */
public static Bitmap getViewBitmap(View view) {
    view.measure(View.MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), View.MeasureSpec.EXACTLY));
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache(true);
    return view.getDrawingCache(true);
}
 
Example 9
Source Project: likequanmintv   File: Blur.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source Project: likequanmintv   File: BlurTask.java    License: Apache License 2.0 5 votes vote down vote up
public BlurTask(View target, BlurFactor factor, Callback callback) {
  target.setDrawingCacheEnabled(true);
  this.res = target.getResources();
  this.factor = factor;
  this.callback = callback;

  target.destroyDrawingCache();
  target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
  capture = target.getDrawingCache();
  contextWeakRef = new WeakReference<>(target.getContext());
}
 
Example 11
Source Project: ColorReference   File: TransitionHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static Bitmap takeSnapshot(View view) {
    view.setDrawingCacheEnabled(true);
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO);

    Bitmap snapshot = null;
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap != null) {
        snapshot = Bitmap.createBitmap(cacheBitmap);
        view.setDrawingCacheEnabled(false);
        view.destroyDrawingCache();
    }
    return snapshot;
}
 
Example 12
Source Project: Blurry   File: Blur.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source Project: Blurry   File: BlurTask.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 14
Source Project: MyBlogDemo   File: Blur.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 15
Source Project: MyBlogDemo   File: BlurTask.java    License: Apache License 2.0 5 votes vote down vote up
public BlurTask(View target, BlurFactor factor, Callback callback) {
  target.setDrawingCacheEnabled(true);
  this.res = target.getResources();
  this.factor = factor;
  this.callback = callback;

  target.destroyDrawingCache();
  target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
  capture = target.getDrawingCache();
  contextWeakRef = new WeakReference<>(target.getContext());
}