我有本地保存到应用程序的专用存储的文件。我已经验证了它的存在,但是每当我打电话BitmapFactory.de codeFILE它总是返回null。
如果我将文件保存为一个资源,并使用ImageView的setImageResource,它总是显示的罚款。
这是什么问题?
下面的代码片段:
=文件名test.png;
如果(doesFileExist(文件名))
位图BMAP = BitmapFactory.de codeFILE(文件名);
我也试过:
位图BMAP = BitmapFactory.de codeFILE(getFilesDir()。getPath()
+文件名);
解决方案
这个问题之前已经等在这里得到解答: BitmapFactory.de$c$cFile返回null即使图像存在
这正是我所需要的:
字符串FNAME =新的文件(getFilesDir(),test.png)getAbsolutePath()。
I have a file saved locally into the application's private storage. I have verified it exists, however whenever I call BitmapFactory.decodeFile it always returns null.
If I save the file as a resource and use ImageView setImageResource, it always shows up fine.
What is the problem?
Here is the snippet:
filename = "test.png";
if (doesFileExist(filename))
Bitmap bMap = BitmapFactory.decodeFile(filename);
I've also tried:
Bitmap bMap = BitmapFactory.decodeFile(getFilesDir().getPath()
+ filename);
解决方案
This question has been answered before such as here: BitmapFactory.decodeFile returns null even image exists
This was exactly what I needed:
String fname=new File(getFilesDir(), "test.png").getAbsolutePath();