View转化为bitmap

private 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("TTTTTTTTActivity", "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;   
    }  

  

posted @ 2013-07-05 13:50  QG_Li  阅读(244)  评论(0)    收藏  举报