[英]How to import images into an Android project?
I'm using the Kilobolt Android framework. 我正在使用Kilobolt Android框架。 Using a custom Assets class, I'm loading images by using a BitmapFactory
and reading the actual image from an InputStream
. 使用自定义Assets类,我通过使用BitmapFactory
加载图像并从InputStream
读取实际图像。 Now I'm having problems loading the bitmap from the folder, it keeps giving me an IOException
. 现在我在从文件夹加载位图时遇到问题,它一直给我IOException
。
I tried copying my image file directly to the drawable-xxhdpi
folder. 我尝试将图像文件直接复制到drawable-xxhdpi
文件夹。 I don't understand why this isn't working. 我不明白为什么这行不通。
My folders look like this: 我的文件夹如下所示:
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...
If you're trying to get a Bitmap from a drawable in a res/drawable-** folder, you should use BitmapFactory.decodeResource(R.drawable.<drawable id>)
如果尝试从res / drawable-**文件夹中的可绘制对象获取位图,则应使用BitmapFactory.decodeResource(R.drawable.<drawable id>)
Edit: to get the Resources for decodeResource, you need to have a Context (such as an Activity or a Service), call getResources()
to get the Resources object 编辑:要获取资源以使用encodeResource,您需要具有一个上下文(例如Activity或Service),并调用getResources()
以获取Resources对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.