我想读一个位图,我有在我的drawable文件夹,并存储为位图变量,以便我可以设置为背景。最好的方法是使用“文件读取器”吗?喜欢
Bitmap decodeFile (String pathName) method
或者有没有一种方法可以这样设置:
Bitmap bmp = R.drawable."bitmapFileName";
(我试过了,但是返回了一个int,只是想知道我是否在正确的轨道上)
任何帮助都很好:)
最佳答案
实际上,R.drawable."bitmapFileName"
只是一个整数,因为它是项目r类的索引(静态整数)(请参阅更多here)。您可以从资源文件夹中加载位图,如下所示:
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.yourBitmap);
我在Android Development Community找到了这个代码。