https://github.com/scionoftech/convertviewtoimage
Convert layout to bitmap image.
https://github.com/scionoftech/convertviewtoimage
Last synced: 3 months ago
JSON representation
Convert layout to bitmap image.
- Host: GitHub
- URL: https://github.com/scionoftech/convertviewtoimage
- Owner: scionoftech
- License: mit
- Created: 2016-09-28T07:04:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-28T17:20:49.000Z (over 9 years ago)
- Last Synced: 2025-05-18T05:13:46.868Z (8 months ago)
- Language: Java
- Size: 16.1 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#ConvertViewtoImage
Convert layout to bitmap image.
```java
view.setDrawingCacheEnabled(true);
// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false); // clear drawing cache
```
## License
[MIT](LICENSE)