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


Java View.buildDrawingCache方法代码示例

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


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

示例1: snapShotWithoutStatusBar

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

示例2: snapShotWithoutStatusBar

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

}
 
开发者ID:codeccc,项目名称:baselibrary-master,代码行数:26,代码来源:ScreenUtils.java

示例3: snapShotWithoutStatusBar

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

示例4: getShareBitmap

import android.view.View; //导入方法依赖的package包/类
private Bitmap getShareBitmap(String text, int textSize) {
    View view = getLayoutInflater().inflate(R.layout.layout_text_card, (ViewGroup) findViewById(android.R.id.content), false);
    TextView textView = (TextView) view.findViewById(R.id.text);
    textView.setText(text);
    textView.setTextSize(textSize);

    view.setDrawingCacheEnabled(true);

    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.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false); // clear drawing cache

    return b;
}
 
开发者ID:auv1107,项目名称:TextEmoji,代码行数:19,代码来源:ShareActivity.java

示例5: 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

示例6: 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:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:18,代码来源:ScreenUtils.java

示例7: 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:weiwenqiang,项目名称:GitHub,代码行数:54,代码来源:ConvertUtils.java

示例8: 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:SiberiaDante,项目名称:EmotionApp,代码行数:21,代码来源:ScreenUtils.java

示例9: 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:gaolhjy,项目名称:cniao5,代码行数:20,代码来源:ScreenUtils.java

示例10: 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:codeccc,项目名称:baselibrary-master,代码行数:21,代码来源:ScreenUtils.java

示例11: 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 = BarUtils.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:imliujun,项目名称:LJFramework,代码行数:21,代码来源:ScreenUtils.java

示例12: getScreenShut

import android.view.View; //导入方法依赖的package包/类
/**
 * 保存截图到sd卡 并返回截图路径
 * @param activity
 * @return
 */
public String getScreenShut(Activity activity){
	View view = activity.getWindow().getDecorView();
	view.setDrawingCacheEnabled(true);
	view.buildDrawingCache();
	Bitmap b1 = view.getDrawingCache();
	// 获取状态栏高度
	Rect frame = new Rect();
	activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
	int statusBarHeight = frame.top;
	// 获取屏幕长和高
	int width = activity.getWindowManager().getDefaultDisplay().getWidth();
	int height = activity.getWindowManager().getDefaultDisplay()
			.getHeight();
	// 去掉标题栏
	Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height
			- statusBarHeight);
	view.destroyDrawingCache();
	//保存到sd卡
	String  sdCardRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
	String fileName = "shareIMG"+new Date().getTime()+".png";
	String path = sdCardRoot+"/HuoCheXing/shareImage/"+fileName;
	if(saveBitmapToSDCard(b,path)){
		return path;
	}
	return null;
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:32,代码来源:ShareUtil.java

示例13: 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

示例14: convertViewToBitmap

import android.view.View; //导入方法依赖的package包/类
public static Bitmap convertViewToBitmap(View view) {
    if (view.getLayoutParams() == null) {
        view.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
    }

    measureView(view);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    view.destroyDrawingCache();
    view.buildDrawingCache();
    return view.getDrawingCache();
}
 
开发者ID:Tamicer,项目名称:FilterBar,代码行数:12,代码来源:UIUtil.java

示例15: takeScreenShot

import android.view.View; //导入方法依赖的package包/类
private Bitmap takeScreenShot(Activity context) {
    View view = context.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap screenBitmap = view.getDrawingCache();
    view.destroyDrawingCache();
    view.setDrawingCacheEnabled(false);
    return screenBitmap;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:10,代码来源:FileUtils.java


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