文件上传图片android

时间:2013-11-27 10:03:03

标签: android image upload directory drawable

我用imageview开发应用程序,我的问题是当我点击按钮加载图片,然后会显示图库,然后我想将所选图像复制到res / drawable android,是否可能?如果是,可以给我源代码吗? 的问候,

2 个答案:

答案 0 :(得分:1)

你无法写入res / drawable。您可以下载可以存储在SD卡中的图像,但不能动态地将图像添加到可绘制文件夹中。

答案 1 :(得分:0)

我害怕res /只是在运行时是只读的。相反,他们在我们的应用程序空间中为我们提供选项或创建文件和我们的个人数据

=====

File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/app_name");
dir.mkdirs();
File file = new File(dir, "myAppData.jpg");

try {
    FileOutputStream f = new FileOutputStream(file);
    PrintWriter pw = new PrintWriter(f);
    pw.println(bytes);// bytes would be data from the source file
    pw.flush();
    pw.close();
    f.close();
} catch (FileNotFoundException e) {
    //..
} catch (IOException e) {
    //...
}