我如何保存图像为一个RelativeLayout的 [英] How can i save image as a RelativeLayout

查看:89
本文介绍了我如何保存图像为一个RelativeLayout的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存相对布局作为位图图像....? 在运行时,我将图像添加到相对布局..然后如何将其保存为位图图像。

我对这个概念不知道......请建议的解决方案这一点。

感谢你。

解决方案

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
   机器人:ID =@ + ID / rlid
   机器人:layout_width =FILL_PARENT
   机器人:layout_height =FILL_PARENT/>

查看内容= findViewById(R.id.rlid);
content.setDrawingCacheEnabled(真正的);
点阵位图= content.getDrawingCache();
档案文件=新的文件(/ SD卡/+ yourimagename +巴纽);
尝试 {
    如果(!file.exists()){
        file.createNewFile();
    }
    FileOutputStream中的ostream =新的FileOutputStream(文件);
    bitmap.com preSS(比较pressFormat.PNG,10,ostream的);
    ostream.close();
    content.invalidate();
}赶上(例外五){
    e.printStackTrace();
} 最后 {
        content.setDrawingCacheEnabled(假);
}
 

How to save an relative layout as an bitmap image....? on run time I am adding images to relative layout.. then how to save it as an Bitmap Image.

I have no Idea on this concept... Please suggest the solutions for this.

Thank You.

解决方案

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/rlid"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"/>

View content = findViewById(R.id.rlid);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/" + yourimagename + ".png");
try {
    if (!file.exists()) {
        file.createNewFile();
    }
    FileOutputStream ostream = new FileOutputStream(file);
    bitmap.compress(CompressFormat.PNG, 10, ostream);
    ostream.close();
    content.invalidate();
} catch (Exception e) {
    e.printStackTrace();
} finally {
        content.setDrawingCacheEnabled(false);
}

这篇关于我如何保存图像为一个RelativeLayout的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆