首页 > 其他 > 详细

将View转换成Bitmap

时间:2014-07-10 21:31:22      阅读:358      评论:0      收藏:0      [点我收藏+]
	/**
	 * 将中间的View保转换成Bitmap
	 * 
	 */
	private Bitmap saveViewBitmap(View view) {
		// get current view bitmap
		view.setDrawingCacheEnabled(true);
		view.buildDrawingCache(true);
		Bitmap bitmap = view.getDrawingCache(true);

		Bitmap bmp = duplicateBitmap(bitmap);
		if (bitmap != null && !bitmap.isRecycled()) {
			bitmap.recycle();
			bitmap = null;
		}
		// clear the cache
		view.setDrawingCacheEnabled(false);
		
		return bmp;
	}

	public static Bitmap duplicateBitmap(Bitmap bmpSrc) {
		if (null == bmpSrc) {
			return null;
		}

		int bmpSrcWidth = bmpSrc.getWidth();
		int bmpSrcHeight = bmpSrc.getHeight();

		Bitmap bmpDest = Bitmap.createBitmap(bmpSrcWidth, bmpSrcHeight,
				Config.ARGB_8888);
		if (null != bmpDest) {
			Canvas canvas = new Canvas(bmpDest);
			final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight);

			canvas.drawBitmap(bmpSrc, rect, rect, null);
		}

		return bmpDest;
	}

将View转换成Bitmap,布布扣,bubuko.com

将View转换成Bitmap

原文:http://blog.csdn.net/changhuiyuanh/article/details/37599401

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!