當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。