/** * 把View绘制到Bitmap上 * @param view 需要绘制的View * @param width 该View的宽度 * @param height 该View的高度 * @return 返回Bitmap对象 */ public static Bitmap getBitmapFromView(View view,int width,int height) { int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY); view.measure(widthSpec, heightSpec); view.layout(0, 0, width, height); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; }
原文地址:http://blog.csdn.net/zhoumushui/article/details/42127681