获取存储在文件夹中绘制从位图信息位图、文件、夹中、信息

2023-09-07 16:38:38 作者:裙裳

我想读入位图我有我绘制的文件夹并将其存储为一个位图变量,这样我可以把它作为背景。请问这样做是最好的方式使用文件阅读器?像

I wanna read in a bitmap that I have in my drawable folder and store it as a Bitmap variable so that I can set it as a background. Would the best way to do this be using a "file reader"? like

  Bitmap decodeFile (String pathName) method

还是有办法只有这样设置:

Or is there a way to just set it like this:

  Bitmap bmp = R.drawable."bitmapFileName"; 

(我曾经试过,但返回一个int,只是想知道如果我是正确的轨道上)

(I have tried this but returns an int, just wondering if I was on the right track)

任何帮助将是巨大的:)

Any help would be great :)

推荐答案

R.drawable。bitmapFileName,着实只是一个整数,它是一个指数(静态整数)在项目的R舱(详见这里)。您可以从资源的文件夹中加载的位图是这样的:

The R.drawable."bitmapFileName" is, indeed, just an integer, for it is an index (static integer) at your project's R class (see more here). You can load your bitmap from the resources's folder like this:

Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.yourBitmap);

我发现在 Android的发展共同体这code。