这里只记录一些链接,对于我的需求,只需要,
public static String createScreenShot(View v) { //测试截屏功能 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 ""; } }
用view getdrawingcache来截图(需求是只需要截特定的一部分),但是这样的图是没有背景的,所以 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); 是用canvas来绘制背景和图,,测试Ok
其他的截图文章: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