Android screenshot capture method

Source: Internet
Author: User
/*** Screenshot method ** @ Param view * @ Param path * @ Param filename */public static Boolean takescreenshot (view, string path) {Boolean issucc = false; /*** to obtain its cache, you must first enable the cache using the setdrawingcacheenable method. * Then call the getdrawingcache method to obtain the cache image of the view. * The builddrawingcache method does not need to be called, because when the getdrawingcache method is called, * If the cache is not created, the system automatically calls the builddrawingcache method to generate the cache. * To update the cache, you must call the destorydrawingcache method to destroy the old cache. * to create a new cache. */View. setdrawingcacheenabled (true); // enable cache view retrieval. builddrawingcache (); Bitmap bitmap = view. getdrawingcache (); // get the view's cache canvas = new canvas (Bitmap); int W = bitmap. getwidth (); int H = bitmap. getheight (); paint = new paint (); paint. setcolor (color. yellow); simpledateformat simple = new simpledateformat ("yyyymmddhhmmss"); string time = simple. format (new date (); // canvas. drawtext (time, w-w/2, H- H/10, paint); canvas. Save (); canvas. Restore (); fileoutputstream Fos = NULL; try {file sddir = new file (PATH); If (! Sddir. exists () {sddir. mkdir ();} file = new file (path + time + ". jpg "); Fos = new fileoutputstream (File); If (FOS! = NULL) {bitmap. compress (bitmap. compressformat. JPEG, 100, FOS); FOS. close (); issucc = true ;}} catch (exception e) {e. printstacktrace ();} return issucc ;}

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.