当前位置: 首页>>代码示例>>Java>>正文


Java View.getDrawingCache方法代码示例

本文整理汇总了Java中android.view.View.getDrawingCache方法的典型用法代码示例。如果您正苦于以下问题:Java View.getDrawingCache方法的具体用法?Java View.getDrawingCache怎么用?Java View.getDrawingCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.View的用法示例。


在下文中一共展示了View.getDrawingCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createBitmapFromView

import android.view.View; //导入方法依赖的package包/类
/**
     * 得到传入的view的bitmap
     * @param view
     * @return
     */
    @Deprecated
    public static Bitmap createBitmapFromView(View view) {
        Bitmap bitmap;
//        Rect rect = new Rect();
//        view.getGlobalVisibleRect(rect);

        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap src = view.getDrawingCache();
        bitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight());
        view.destroyDrawingCache();
        view.setDrawingCacheEnabled(false);
        src.recycle();
        src = null;
        return bitmap;
    }
 
开发者ID:halohoop,项目名称:UsoppBubble,代码行数:22,代码来源:Utils.java

示例2: getViewBitmap

import android.view.View; //导入方法依赖的package包/类
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;
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:28,代码来源:DragDropHelper.java

示例3: takeScreenShot

import android.view.View; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public static Bitmap takeScreenShot(Activity pActivity) {
    View view = pActivity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    Rect frame = new Rect();
    view.getWindowVisibleDisplayFrame(frame);
    int stautsHeight = frame.top;
    Point size = new Point();
    Display display = pActivity.getWindowManager().getDefaultDisplay();
    if (VERSION.SDK_INT < 13) {
        size.set(display.getWidth(), display.getHeight());
    } else {
        pActivity.getWindowManager().getDefaultDisplay().getSize(size);
    }
    return Bitmap.createBitmap(bitmap, 0, stautsHeight, size.x, size.y - stautsHeight);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:BitmapUtil.java

示例4: captureWithoutStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,不包含状态栏
 *
 * @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 = BarTool.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;
}
 
开发者ID:Ayvytr,项目名称:EasyAndroid,代码行数:21,代码来源:ScreenTool.java

示例5: snapShotWithStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,包含状态栏
 *
 * @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;
}
 
开发者ID:zhudongya123,项目名称:WechatChatroomHelper,代码行数:19,代码来源:ScreenUtils.java

示例6: getBitmapOFActivity

import android.view.View; //导入方法依赖的package包/类
public static Bitmap getBitmapOFActivity(Context context) {
	if (context == null) {
		return null;
	}
	if (!(context instanceof Activity)) {
		return null;
	}
	Activity activity = (Activity) context;
	View rootview = activity.getWindow().getDecorView().getRootView();
	rootview.setDrawingCacheEnabled(true);
	Bitmap bitmap = rootview.getDrawingCache();
	return bitmap;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:14,代码来源:ImageUtils.java

示例7: createFloatView

import android.view.View; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:free46000,项目名称:MultiItem,代码行数:16,代码来源:DragFloatViewHelper.java

示例8: toBitmap

import android.view.View; //导入方法依赖的package包/类
/**
 * 把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;
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:54,代码来源:ConvertUtils.java

示例9: drawChild

import android.view.View; //导入方法依赖的package包/类
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    boolean result;
    LayoutParams lp = (LayoutParams) child.getLayoutParams();
    int save = canvas.save(2);
    if (!(!this.mCanSlide || lp.slideable || this.mSlideableView == null)) {
        canvas.getClipBounds(this.mTmpRect);
        if (isLayoutRtlSupport()) {
            this.mTmpRect.left = Math.max(this.mTmpRect.left, this.mSlideableView.getRight());
        } else {
            this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft());
        }
        canvas.clipRect(this.mTmpRect);
    }
    if (VERSION.SDK_INT >= 11) {
        result = super.drawChild(canvas, child, drawingTime);
    } else if (!lp.dimWhenOffset || this.mSlideOffset <= 0.0f) {
        if (child.isDrawingCacheEnabled()) {
            child.setDrawingCacheEnabled(false);
        }
        result = super.drawChild(canvas, child, drawingTime);
    } else {
        if (!child.isDrawingCacheEnabled()) {
            child.setDrawingCacheEnabled(true);
        }
        Bitmap cache = child.getDrawingCache();
        if (cache != null) {
            canvas.drawBitmap(cache, (float) child.getLeft(), (float) child.getTop(), lp.dimPaint);
            result = false;
        } else {
            Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
            result = super.drawChild(canvas, child, drawingTime);
        }
    }
    canvas.restoreToCount(save);
    return result;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:37,代码来源:SlidingPaneLayout.java

示例10: captureWithStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,包含状态栏
 *
 * @param activity activity
 * @return Bitmap
 */
public static Bitmap captureWithStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    Bitmap ret = Bitmap.createBitmap(bmp, 0, 0, dm.widthPixels, dm.heightPixels);
    view.destroyDrawingCache();
    return ret;
}
 
开发者ID:Jay-Ping,项目名称:newIPlay,代码行数:18,代码来源:ScreenUtils.java

示例11: captureWithoutStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,不包含状态栏
 * <p>需要用到上面获取状态栏高度的方法
 */
public static Bitmap captureWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    int statusBarHeight = getStatusBarHeight(activity);
    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bp;
}
 
开发者ID:zhuangzaiku,项目名称:AndroidCollection,代码行数:17,代码来源:ScreenUtils.java

示例12: snapShotWithStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,包含状态栏
 *
 * @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;

}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:20,代码来源:ScreenUtil.java

示例13: of

import android.view.View; //导入方法依赖的package包/类
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;
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:10,代码来源:Blur.java

示例14: snapShotWithStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,包含状态栏
 * 
 * @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;

}
 
开发者ID:ChenTianSaber,项目名称:DailyZhiHu,代码行数:21,代码来源:ScreenUtils.java

示例15: snapShotWithStatusBar

import android.view.View; //导入方法依赖的package包/类
/**
 * 获取当前屏幕截图,包含状态栏(这个方法没测试通过)
 * 
 * @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;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:19,代码来源:DisplayUtil.java


注:本文中的android.view.View.getDrawingCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。