程序员人生 网站导航

Android--将布局保存成图像

栏目:综合技术时间:2014-10-10 08:00:00
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();

------分隔线----------------------------

上一篇 mkdir

下一篇 MyEclipse常用快捷键

------分隔线----------------------------

最新技术推荐