繁体   English   中英

如何将图像导入Android项目?

[英]How to import images into an Android project?

我正在使用Kilobolt Android框架。 使用自定义Assets类,我通过使用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-**文件夹中的可绘制对象获取位图,则应使用BitmapFactory.decodeResource(R.drawable.<drawable id>)

编辑:要获取资源以使用encodeResource,您需要具有一个上下文(例如Activity或Service),并调用getResources()以获取Resources对象

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM