Cri*_*ian 11
您必须将图像放在res/drawable文件夹中.然后,您可以使用:( R.drawable.name_of_imagefor 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();
}
Run Code Online (Sandbox Code Playgroud)
如果要保存以编程方式创建的图像,可以执行以下操作:
try {
FileOutputStream out = new FileOutputStream(context.getFilesDir().getAbsolutePath()+"/imagename.png");
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
您无法将其保存到项目目录中.我建议你阅读有关android包如何工作的文档,因为它似乎你不明白.