Code example for Picture

Methods: draw, getHeight, getWidth

0
 
	public static Bitmap loadBitmapFromViewByCapture(Context context,WebView v) {
		long time = System.currentTimeMillis();
 
		Picture picture = v.capturePicture();
		int width = picture.getWidth();
		int height = picture.getHeight();
		Bitmap bitmap = null;
		Bitmap bt = null;
		if (width > 0 && height > 0) {
			// 创建指定高宽的Bitmap对象 
			bitmap = Bitmap
					.createBitmap( width, height, Bitmap.Config.ARGB_8888);
			 
						// 创建Canvas,并以bitmap为绘制目标 
			 
			Canvas canvas = new Canvas(bitmap);
			// 将WebView影像绘制在Canvas上 
			picture.draw(canvas);
			bt = Bitmap.createScaledBitmap(bitmap, ArtBookUtils.dip2px(context, width), ArtBookUtils.dip2px(context, height), true);
 
			if(bitmap!=null){
				bitmap.recycle();
				bitmap = null;