[英]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.