Android 将布局文件转成图片(将View 转换成BitMap)

public Bitmap getViewBitmap(int layoutId) {
View view = getLayoutInflater().inflate(layoutId, null);
int me = MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED);
view.measure(me,me);
view.layout(0 ,0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();

       return bitmap;
}
常用在百度地图

你可能感兴趣的:(安卓)