Screenshots of the android View

Source: Internet
Author: User

There are a lot of software on PC, but there are few on Android, so I wrote one myself. The following is the core code of the software: Private bitmap getviewbitmap (view V) {// convert a view into an image

V. clearfocus (); // clear view focus
V. setpressed (false); // set the view to not clickable

Boolean willnotcache = V. willnotcachedrawing (); // whether the returned view can save its drawing Cache
V. setwillnotcachedrawing (false );

// Reset the drawing cache background color to fully transparent
// For the duration of this operation // set the view to transparent during this operation
Int color = V. getdrawingcachebackgroundcolor (); // obtain the background color of the cached bitmap.
V. setdrawingcachebackgroundcolor (0); // set the drawing background color.
If (color! = 0) {// If the obtained background is not black, release the previous drawing cache.
V. destroydrawingcache (); // release the cache used by the drawing Resource
}
V. builddrawingcache (); // recreate the drawing cache. The background color is black.
Bitmap cachebitmap = V. getdrawingcache (); // cache the drawing. Note that only an image is referenced here.
If (cachebitmap = NULL ){
Return NULL;
}
Bitmap bitmap = bitmap. createbitmap (cachebitmap); // instantiate a bitmap.
// Restore the view
V. destroydrawingcache (); // release the bitmap memory.
V. setwillnotcachedrawing (willnotcache); // return the previous cache settings
V. setdrawingcachebackgroundcolor (color); // return the previous cache color settings
Return bitmap;

}

Http://xiangqianppp-163-com.iteye.com/blog/1457688

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.