Some ways to capture Android screenshots

Source: Internet
Author: User

Here are only a few links to record, for my needs, just need,

public static String Createscreenshot (View v)     {      //test screenshot function    SimpleDateFormat SDF = new SimpleDateFormat (  "Yyyy-mm-dd_hh-mm-ss", locale.us);    String Dirpath=mapplication.sdpath+constants.qz_path;    file Dirfile=new file (Dirpath);    if (!dirfile.exists ())    {    dirfile.mkdir ();   }      String  fname = Mapplication.sdpath+constants.qz_path+sdf.format (New Date ()) + ". png";           v.setdrawingcacheenabled (true);     V.builddrawingcache ();      Bitmap bitmap = V.getdrawingcache ();      if (bitmap  != null)    {           Bitmap Bmpall=bitmap.createbitmap (mapplication.screen[0],commonfun.dip2px (Mapplication.getcontext (), 250), config.argb_8888);                 canvas canvas=new canvas (bmpall);       Bitmap bmp1 = Bitmapfactory.decoderesource (Mapplication.getcontext (). Getresources () , R.DRAWABLE.PB_SCORE_BG);       Canvas.drawbitmap (bmp1,0,0,null);

      Canvas.drawbitmap (bitmap,0,0,null);

            System.out.println ("bitmap got!");             try{               fileoutputstream  out = new FileOutputStream (fname);               bmpall.compress ( Bitmap.compressformat.png,100, out);               System.out.println ("file" + fname + "Output done.");               return fname;            }catch (exception e) {               E.printstacktrace ();               return "";            }          }else{             System.out.println ("Bitmap s null!");             return "";          }      }

With the view Getdrawingcache (the requirement is only required to intercept a specific part), but such a diagram is without background, so canvas canvas=new canvas (bmpall);       Bitmap bmp1 = Bitmapfactory.decoderesource (Mapplication.getcontext (). Getresources (), R.DRAWABLE.PB_SCORE_BG); Canvas.drawbitmap (Bmp1,0,0,null);

Canvas.drawbitmap (Bitmap,0,0,null); is to use canvas to draw the background and graph, test OK

Other articles: Http://veikr.com/201202/android_screen_shot.html http://blog.csdn.net/jokers_i/article/details/39549633

http://blog.csdn.net/xu_fu/article/details/39268771 http://blog.csdn.net/woshinia/article/details/11520403

Some ways about Android

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.