Android: Fix view.getdrawingcache () return null problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.