【发布时间】:2011-05-19 05:20:19
【问题描述】:
我想将我的位图图像存储到项目目录中。我怎样才能访问我的项目文件夹或我的项目文件夹的地址是什么?
【问题讨论】:
标签: android image file directory store
我想将我的位图图像存储到项目目录中。我怎样才能访问我的项目文件夹或我的项目文件夹的地址是什么?
【问题讨论】:
标签: android image file directory store
您必须将图像放在res/drawable 文件夹中。然后,您可以使用以下方式访问它们:R.drawable.name_of_image(对于name_of_image.png 或name_of_image.jpg)。
如果您想通过原始名称访问它们,最好将它们保存在assets 文件夹中。然后,您可以使用AssetManager 访问它们:
AssetManager am = getResources().getAssets();
try {
InputStream is = am.open("image.png");
// use the input stream as you want
} catch (IOException e) {
e.printStackTrace();
}
如果您想保存以编程方式创建的图像,您可以这样做:
try {
FileOutputStream out = new FileOutputStream(context.getFilesDir().getAbsolutePath()+"/imagename.png");
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
}
您无法将其保存到您的项目目录中。我建议您阅读有关 android 包如何工作的文档,因为您似乎不明白。
【讨论】:
context的?