/**截屏操作 * * 把图片保存到SD卡 */ private void ScreenShot(View v,String fileName){ View view = v.getRootView(); view.setDrawingCacheEnabled(true); Bitmap bitmap = view.getDrawingCache(); FileOutputStream fos = null; File dirFile = new File(DIRPATH); if(!dirFile.exists()){ dirFile.mkdir(); } try { fos = new FileOutputStream(new File(DIRPATH + FILENAME)); if (null != fos) { bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
截屏操作二:
public static void screenView(View view,String fileName){ Bitmap sCoverBitmap = Bitmap.createBitmap( view.getWidth(),view.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(sCoverBitmap); view.draw(canvas); FileOutputStream fos = null; File dirFile = new File(StaticData.PATH); if(!dirFile.exists()){ dirFile.mkdir(); } try { File file = new File(StaticData.PATH,fileName); fos = new FileOutputStream(file); if (null != fos) { sCoverBitmap.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }