我想将我的位图图像存储到项目目录中。我如何访问我的项目文件夹或者我的项目文件夹的地址是什么?
您必须将图像放入res/drawable
文件夹。然后,您可以使用以下方式访问它们:R.drawable.name_of_image
(for name_of_image.png
or 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 包如何工作的文档,因为你似乎不明白。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)