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