How to convert Views to bitmaps?

I used to use the buildDrawingCache() method to get a bitmap of my layout, but I was having trouble with it when the view was large. Now I use the following method:

FrameLayout view = findViewById(R.id.framelayout);
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);

How to convert View into Bitmap

FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);

view.setDrawingCacheEnabled(true);

view.buildDrawingCache();

Bitmap bm = view.getDrawingCache();

Tags:

Android

Bitmap