黑莓res文件夹命名约定 [英] Blackberry res folder naming convention
问题描述
我创造了这样一个静态函数。
I created a static function like this.
public static Bitmap Bitmap(String path) {
Bitmap bitmap = Bitmap
.getBitmapResource(Display.getWidth() + "/" + path);
System.out.println(Display.getWidth() + "" + path);
return bitmap;
}
然而,当我这样调用,
However, when I called like this,
private Bitmap download = Config_GlobalFunction.Bitmap("btn_download.png");
输出给了我 FRIDG找不到320 / btn_download.png
。
在我的 RES
文件夹中,我得到了这是一个文件夹 IMG
并在 IMG
得了这是 160
, 240
, 320 6种不同的文件夹
, 360
, 480
和 640
文件夹中。
In my res
folder, I got an folder which was img
and inside img
got 6 different folders which were 160
, 240
, 320
, 360
, 480
and 640
folder.
我如何可以调用正确的基于 Display.getWidth文件夹中的形象()
?
How can I call correct folder's image based on Display.getWidth()
?
推荐答案
它的是可能有 / RES
文件夹下的文件夹层次结构但必须使用的getClass()。的getResourceAsStream(路径)
,而不是 Bitmap.getBitma $ p $的PSource()
中为了创建您的资源。
It is possible to have a folder hierarchy under the /res
folder but you must use getClass().getResourceAsStream(path)
rather than Bitmap.getBitmapResource()
in order to create your resource.
该示例从路径 /res/img/hi_res/ui/action_arrow.png
A位图:
This example creates a Bitmap from the path /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);
这是一个多一点的工作,但它确实意味着你可以有一个很好的文件夹结构,而不是数百张照片放在一起在一个单一的文件夹中。
It's a bit more work but it does mean you can have a nice folder structure, rather than hundreds of images lumped together in a single folder.
这篇关于黑莓res文件夹命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!