无法将图像从原始图像加载到imageview [英] Can't load image from raw to imageview

查看:312
本文介绍了无法将图像从原始图像加载到imageview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用setImageResource从原始文件夹加载图像到imageview,但是我得到了drawable错误类型的Expected资源.

I want to load image using setImageResource, from raw folder to imageview, But I get Expected resource of type drawable error.

我正在使用android studio,在此之前,当我使用Eclipse时,一切都很好.我不想使用可绘制文件夹.

I'm using android studio, Before that when I was using Eclipse everything was fine. I don't want to use drawable folder.

原始文件夹:

有什么建议吗?谢谢

推荐答案

我想使用setImageResource从原始文件夹加载图像到imageview,但是我得到了drawable错误类型的Expected资源.

I want to load image using setImageResource, from raw folder to imageview, But I get Expected resource of type drawable error.

setImageResource()使用原始资源没有记录的行为.

Using a raw resource for setImageResource() is not documented behavior.

在我使用Eclipse之前,一切都很好

Before that when I was using Eclipse everything was fine

并非如此.在您的代码运行时,它可能无法在所有过去,现在和将来的Android版本上使用.这就是为什么出现编译器警告的原因.

Not really. While your code runs, it might not on all past, present, and future versions of Android. This is why there is a compiler warning.

因为可绘制的按比例缩小图像取决于设备

because drawable scaled down images depend of device

drawable-nodpi 用于不应该根据屏幕密度缩放的可绘制对象.通常这不是一个好主意,但也许您有理由.

Use drawable-nodpi for drawables that should not be scaled based upon screen density. That is usually not a good idea, but perhaps you have a reason for it.

使用原始资源的一种更安全的方法是在 Resources 上使用 openRawResource()来获得 InputStream ,然后使用 BitmapFactory 以读取位图.

A safer approach for using a raw resource would be to use openRawResource() on Resources to get an InputStream, then use BitmapFactory to read in the bitmap.

欢迎您使用 @SuppressWarnings("ResourceType")禁止显示警告,但是当您的应用停止运行时,请不要抱怨.

You are welcome to suppress the warning with @SuppressWarnings("ResourceType"), but do not complain when your app stops working.

这篇关于无法将图像从原始图像加载到imageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆