您的位置:首页 > 其它

View生成Bitmap

2016-04-24 18:00 405 查看
高德地图对自定义Marker的处理,它是通过把我们的自定义View生成Bitmap,然后把图片放到地图中。

/**
* view转化为图片
*
* @param context
* @param var0
* @return
*/
public static Bitmap convertViewToBitmap(Context context, View view) {
try {
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.addView(view);
frameLayout.setDrawingCacheEnabled(true);
checkView(frameLayout);
frameLayout.destroyDrawingCache();
frameLayout.measure(View.MeasureSpec.makeMeasureSpec(0, 0), View.MeasureSpec.makeMeasureSpec(0, 0));
frameLayout.layout(0, 0, frameLayout.getMeasuredWidth(), frameLayout.getMeasuredHeight());
Bitmap bitmap = frameLayout.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
return bitmap;
} catch (Throwable var2) {
az.a(var2, "Utils", "getBitmapFromView");
var2.printStackTrace();
return null;
}
}

private static void checkView(View view) {
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); ++i) {
b(((ViewGroup) view).getChildAt(i));
}
} else if (view instanceof TextView) {
((TextView) view).setHorizontallyScrolling(false);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: