View view = findViewById(R.id.photoselectbg_iv_rl11); //获取布局控件属性 final Bitmap bmp = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.RGB_8888); view.draw(new Canvas(bmp)); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); String time = dateFormat.format(new Date()); File dir = new File(GloableParams.IMG_FILE_PATH); if (!dir.exists()) { dir.mkdirs(); } final String photoUrl = GloableParams.IMG_FILE_PATH + time + ".png";//换成自己的图片保存路径 final File file = new File(photoUrl); new Thread() { @Override public void run() { try { boolean bitMapOk = bmp.compress(CompressFormat.PNG, 100, new FileOutputStream(file)); if(bitMapOk) { myApp.photoFile = file; myApp.photoUrl = photoUrl; } catch (FileNotFoundException e) { e.printStackTrace(); } } }.start();
核心就是view.draw();
时间: 2024-11-05 21:34:28