安卓:德codeFILE始终在内部存储的文件返回null [英] Android: decodeFile always returns null for file in internal storage

查看:155
本文介绍了安卓:德codeFILE始终在内部存储的文件返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有本地保存到应用程序的专用存储的文件。我已经验证了它的存在,但是每当我打电话BitmapFactory.de codeFILE它总是返回null。

如果我将文件保存为一个资源,并使用ImageView的setImageResource,它总是显示的罚款。

这是什么问题?

下面的代码片段:

  =文件名test.png;

如果(doesFileExist(文件名))
    位图BMAP = BitmapFactory.de codeFILE(文件名);
 

我也试过:

 位图BMAP = BitmapFactory.de codeFILE(getFilesDir()。getPath()
                    +文件名);
 

解决方案

这个问题之前已经等在这里得到解答: <一href="http://stackoverflow.com/questions/3388898/bitmapfactory-de$c$cfile-returns-null-even-image-exists">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();

这篇关于安卓:德codeFILE始终在内部存储的文件返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆