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