Android--将布局保存成图像
来源:程序员人生 发布时间:2014-10-10 08:00:00 阅读次数:3012次
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();
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠