最近业务需要把自定义的View(布局视图)转换成Bitmap输出,请各位高手支招!谢谢
最好有代码哦!!!
最好有代码哦!!!
解决方案 »
- android刷机后用adb连接,显示有root权限,而手机端却无法获取Root权限
- 平板电脑安装android出现问题,高手帮帮忙
- 怎么解决如下错误,小弟在这里谢谢各位了
- 关于android客户端程序开发--->淘宝客户端
- 请教:intent.addCategory 怎么老是提示错误Syntax error??
- android 通过webservice连接服务器 服务器端该如何搭建?
- 如何监听android tab 的长按事件
- Button.OnClickListener与View.OnClickListener的区别
- genymotion模拟器之间的通信
- Viewpager+Fragment listview频繁切换 程序崩溃
- 通过API控制摄像头获取的视频数据非常不清晰,请教下有没其它办法可以实现
- 新手初学android 求高手指导。
View.buildDrawingCache();
Bitmap b = View.getDrawingCache();
需要先确保view已经走过了onDraw或者draw函数。下面是一段没有问题的代码。 private Bitmap getViewBitmap(View v) {
v.clearFocus();
v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent
// for the duration of this operation
int color = v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0); if (color != 0) {
v.destroyDrawingCache();
}
v.buildDrawingCache();
Bitmap cacheBitmap = v.getDrawingCache(); Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); // Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color); return bitmap;
}