Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:将图像存储到项目目录(文件)?_Android_Image_File_Directory_Store - Fatal编程技术网

Android:将图像存储到项目目录(文件)?

Android:将图像存储到项目目录(文件)?,android,image,file,directory,store,Android,Image,File,Directory,Store,我想将位图图像存储到项目目录中。我如何才能访问我的项目文件夹,或者我的项目文件夹的地址是什么?您必须将图像放在res/drawable文件夹中。然后,您可以使用以下命令访问它们:R.drawable.name\u of_image(对于name\u of_image.png或name\u of_image.jpg) 如果要按原始名称访问它们,最好将它们保存在assets文件夹中。然后,您可以使用AssetManager访问它们: AssetManager am = getResources().

我想将位图图像存储到项目目录中。我如何才能访问我的项目文件夹,或者我的项目文件夹的地址是什么?

您必须将图像放在
res/drawable
文件夹中。然后,您可以使用以下命令访问它们:
R.drawable.name\u of_image
(对于
name\u of_image.png
name\u 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软件包工作原理的文档,因为您似乎不明白。

谢谢克里斯蒂安,哦,不。实际上我想将我的图像(通过程序创建的)保存到res/drawable目录中。我读了一张图片,提取了像素,然后我处理了像素,现在我想用另一个名字把它再次保存在这个目录中。这是我的问题,我如何储存这张新照片?谢谢亲爱的克里斯蒂安。我按照你告诉我的那样更改了代码,但当程序到达以下行“FileOutputStream out=new FileOutputStream(context.getFileDir().getAbsolutePath()+”/imagename.png”);“崩溃并跳出。感谢亲爱的克里斯蒂安花费您的时间。这是日志的图片:您是如何初始化
上下文的
?在课程顶部,我写了“上下文上下文”;我也在活动中进行了测试,但结果是一样的。