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); } }
相关文章推荐
- c中数据的存储(内存)
- 从零开始学动态规划
- eclipse开发velocity实例(初学)
- PHP手工注入
- JavaScript常用字符串与数组扩展函数小结
- stc跟踪算法的一点优化
- ERROT: SampleCB() - buffer sizes do not match 解决方案
- jQuery EasyUI基础组件(panel,window,dialog)
- xib文件使用
- Jquery插件写法及extentd函数
- mysql注入 4个参数
- Leetcode 289 Game of Life
- 最大熵模型
- Segments--poj3304(判断直线与线段之间的关系)
- 一个Activity管理多个Fragment切换
- mac下的adt-bundle如何配置jre
- 实用资源推荐分享
- velocity 新手入门
- 用字符串做一个文本编译器
- CV和Resume的区别(转)