In project development, it is sometimes necessary to save the content of a view (including its sub-view) as a picture (similar to), so first think of the View.getdrawingcache () method, which will return a bitmap. But when I'm using it, this method always returns null, and the whole web looked up and needed to set a bunch of parameters, but it still didn't work.
Suddenly think of a change of mind, since access to the content of the view is so difficult, it is better to draw the content of the view directly to another canvas up! So the solution was born, and the pro-test was available:
public static Bitmap Getviewbitmap (view view) { Bitmap Bitmap = Bitmap.createbitmap (View.getlayoutparams (). Width, View.getlayoutparams (). height, Bitmap.Config.ARGB_8888); Canvas canvas = new canvas (bitmap); View.draw (canvas); return bitmap; }Problem Solving!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android: Fix view.getdrawingcache () return null problem