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


Java View.setWillNotCacheDrawing方法代码示例

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


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

示例1: getViewBitmap

import android.view.View; //导入方法依赖的package包/类
public static Bitmap getViewBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0xffffff);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(comBitmap.getLeft(), comBitmap.getTop(), comBitmap.getLeft()+width, comBitmap.getTop()+height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap);
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:41,代码来源:BitmapCommonUtils.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: getBitmapFromView2

import android.view.View; //导入方法依赖的package包/类
/**
 * 把一个View的对象转换成bitmap
 *
 * @param view View
 * @return Bitmap
 */
public static Bitmap getBitmapFromView2(View view) {
    if (view == null) {
        return null;
    }
    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) {
        XPrintUtils.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;
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:36,代码来源:XBitmapUtils.java

示例4: convertViewToBitmap

import android.view.View; //导入方法依赖的package包/类
public static Bitmap convertViewToBitmap(View view) {
    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) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:BitmapUtil.java

示例5: getViewBitmap

import android.view.View; //导入方法依赖的package包/类
public static 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(0);

    if (color != 0) {
        v.destroyDrawingCache();
    }
    v.buildDrawingCache();
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e("Folder", "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;
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:32,代码来源:MyBitmapUtil.java

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

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

示例8: toBitmap

import android.view.View; //导入方法依赖的package包/类
/**
 * convert View to Bitmap.
 *
 * @param view the view
 * @return the bitmap
 * @link http ://www.cnblogs.com/lee0oo0/p/3355468.html
 */
public static Bitmap toBitmap(View view) {
    //以下代码用于把当前view转化为bitmap(截图)
    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();
    cacheBitmap.recycle();
    // Restore the view
    view.destroyDrawingCache();
    view.setWillNotCacheDrawing(willNotCache);
    view.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:55,代码来源:ConvertUtils.java

示例9: getBitmapFromView

import android.view.View; //导入方法依赖的package包/类
private static Bitmap getBitmapFromView(View view, int tryTime, boolean forceHighQuality) {
    boolean willNotCacheDrawingBefore = view.willNotCacheDrawing();
    view.setWillNotCacheDrawing(false);

    int drawingCacheBackgroundColorBefore = view.getDrawingCacheBackgroundColor();
    view.setDrawingCacheBackgroundColor(0);
    int drawingCacheQualityBefore = view.getDrawingCacheQuality();
    if (drawingCacheBackgroundColorBefore != 0) {
        view.destroyDrawingCache();
    }
    if (tryTime > 1) {
        view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
    }
    view.buildDrawingCache();
    Bitmap cacheBitmap = view.getDrawingCache();
    if (cacheBitmap == null || cacheBitmap.isRecycled()) {
        view.setDrawingCacheQuality(drawingCacheQualityBefore);
        view.setWillNotCacheDrawing(willNotCacheDrawingBefore);
        view.setDrawingCacheBackgroundColor(drawingCacheBackgroundColorBefore);

        if (tryTime < TRY_GET_BITMAP_FROM_VIEW_MAX_REPEAT_TIME) {
            handleOutOfMemory();
            return getBitmapFromView(view, tryTime + 1, forceHighQuality);
        }
        return null;
    }

    Bitmap bitmap = createBitmap(cacheBitmap, cacheBitmap.getWidth(), cacheBitmap.getHeight(), forceHighQuality || tryTime == 1 ? Config.ARGB_8888
            : Config.ARGB_4444);

    if (bitmap == cacheBitmap) {
        bitmap = createBitmap(cacheBitmap);
    }

    view.destroyDrawingCache();

    view.setDrawingCacheQuality(drawingCacheQualityBefore);
    view.setWillNotCacheDrawing(willNotCacheDrawingBefore);
    view.setDrawingCacheBackgroundColor(drawingCacheBackgroundColorBefore);

    return bitmap;
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:43,代码来源:BitmapUtils.java


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