最近业务需要把自定义的View(布局视图)转换成Bitmap输出,请各位高手支招!谢谢
最好有代码哦!!!
最好有代码哦!!!
解决方案 »
- Android WiFi porting
- 请问怎么才能直接显示副应用的图标?
- time.setToNow();取当前时间,月份总是不对。
- 现在开发android程序,一般用哪个版本的SDK
- camera 布局
- 关于操作route的default和secondary tabl问题
- 求助:fragment 在横竖屏切换的时候崩溃
- 简单的语法问题
- 求助:camera 中onPreviewFrame(final byte[] data, Camera camera) 关于data的处理
- 关于APK插件的框架开发
- 通过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;
}