Blackberry res folder naming convention

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.

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.

Leave a Comment