安卓:存储图像到项目目录(文件)? [英] Android: Storing Image into project directory (files)?

查看:431
本文介绍了安卓:存储图像到项目目录(文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的位图图像存储到项目目录。我怎么能有机会到我的项目文件夹或什么是我的项目文件夹的地址?

I want to store my Bitmap image into project directory. How can I have access to my project folder or what is the address of my project folder?

推荐答案

您必须把图像中的 RES /绘制文件夹中。 R.drawable.name_of_image (为 name_of_image.png 或<$ C $:那么,您可以通过使用访问它们C> name_of_image.jpg )。

You have to put the images in the res/drawable folder. Then, you can access them by using: R.drawable.name_of_image (for name_of_image.png or name_of_image.jpg).

如果您希望通过自己原来的名字来访问它们,你最好将它们保存在资产文件夹中。然后,您可以通过使用访问它们的 AssetManager

If you want to access them by their original name, you better save them in the assets folder. Then, you can access them by using the AssetManager:

AssetManager am = getResources().getAssets();
try {
    InputStream is = am.open("image.png");
    // use the input stream as you want
} catch (IOException e) {
    e.printStackTrace();
}

如果你想保存一个编程生成的图像,你可以这样做:

If you want to save a programatically created image, you can do:

try {
       FileOutputStream out = new FileOutputStream(context.getFilesDir().getAbsolutePath()+"/imagename.png");
       bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
       e.printStackTrace();
}

您不能将其保存到您的项目目录。我建议你​​阅读有关如何Android包工作的文件,因为它似乎你不明白。

You can't save it to your project directory. I recommend you to read the documentation about how android packages work, because it seems you don't understand.

这篇关于安卓:存储图像到项目目录(文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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