Skip to content

scionoftech/ConvertViewtoImage

Repository files navigation

#ConvertViewtoImage

Convert layout to bitmap image.

      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

About

Convert layout to bitmap image.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages