Ala*_*Lai 2 blackberry naming-conventions
我创建了这样的静态函数.
public static Bitmap Bitmap(String path) {
Bitmap bitmap = Bitmap
.getBitmapResource(Display.getWidth() + "/" + path);
System.out.println(Display.getWidth() + "" + path);
return bitmap;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我打电话的时候,
private Bitmap download = Config_GlobalFunction.Bitmap("btn_download.png");
Run Code Online (Sandbox Code Playgroud)
输出给了我FRIDG could not find 320/btn_download.png
.
在我的res
文件夹中,我得到了这是一个文件夹,img
并且内部img
有哪些人6个不同的文件夹160
,240
,320
,360
,480
和640
文件夹.
如何根据Display.getWidth()
?调用正确的文件夹图像?
这是可能有下的文件夹层次结构/res
文件夹,但你必须使用getClass().getResourceAsStream(path)
,而不是Bitmap.getBitmapResource()
为了创建资源.
此示例从路径创建一个位图/res/img/hi_res/ui/action_arrow.png
:
String imagePath = "/img/hi_res/ui/action_arrow.png";
InputStream is = getClass().getResourceAsStream(imagePath);
byte[] imageBytes = IOUtilities.streamToBytes(is);
Bitmap b = Bitmap.createBitmapFromBytes(imageBytes, 0, imageBytes.length, 1);
Run Code Online (Sandbox Code Playgroud)
这是一个更多的工作,但它确实意味着你可以有一个很好的文件夹结构,而不是数百个图像集中在一个文件夹中.