Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.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
Java 如何将图像导入Android项目?_Java_Android_Image - Fatal编程技术网

Java 如何将图像导入Android项目?

Java 如何将图像导入Android项目?,java,android,image,Java,Android,Image,我正在使用Kilobolt Android框架。使用自定义资产类,我通过使用BitmapFactory加载图像,并从InputStream读取实际图像。现在我从文件夹加载位图时遇到问题,它一直给我一个IOException 我尝试将图像文件直接复制到drawable xxhdpi文件夹。我不明白这为什么不起作用 我的文件夹如下所示: src |--main |---|--java |---|---|--all the fancy java files :D |---|--res |--

我正在使用Kilobolt Android框架。使用自定义资产类,我通过使用
BitmapFactory
加载图像,并从
InputStream
读取实际图像。现在我从文件夹加载位图时遇到问题,它一直给我一个
IOException

我尝试将图像文件直接复制到
drawable xxhdpi
文件夹。我不明白这为什么不起作用

我的文件夹如下所示:

src
 |--main
 |---|--java
 |---|---|--all the fancy java files :D
 |---|--res
 |---|---|--drawable-xxhdpi
 |---|---|---|--fancy images
 |---|---|--other folders and files...
 |---|--other folders and files...
 |--other folders and files...

如果您试图从res/drawable-**文件夹中的drawable获取位图,则应使用
BitmapFactory.decodeResource(R.drawable.)

编辑:要获取decodeResource的资源,您需要有一个上下文(例如活动或服务),调用
getResources()
以获取资源对象
decodeResource()
有两个重载,并且都有一个
Resource
参数。我该怎么处理?()抱歉,如果您有上下文(例如活动或服务),请调用getResources以获取Resources对象。