开发者

Bundling images with Blackberry

How do I get bundled images with the BlackBerry Eclipse Plugin 1.1 Beta? I copied an image into "res/background.jpg" and tried to load it using Bitmap.getBitmapResource on background.jpg. Unfortunately, the image wasn't found (Illegal argument exception). I tried moving my image file into the src folder as per the advice here, but that didn'开发者_C百科t work either. I have opened up the .jar file and the background image is present at the root of the .jar file. The option to convert image files to .png isn't selected either.

Links

  • Could not find sample
  • Library Reference


Two things:

  1. The res folder needs to be a "source directory" in Eclipse. You can achieve this by right-clicking on the folder and going to "Build Path" -> "Use As Source Folder".
  2. When calling Bitmap.getBitmapResource(), like Michael B. said above, you shouldn't put the folder name in the path. Just call Bitmap.getBitmapResource("background.jpg");

Finally, I'm assuming that because your resource is called "background.jpg" you want it to be the background for a Screen. If this is the case, make sure to set the background using the Screen's Main Manager instead of on the screen itself. For example:

public class MyScreen extends MainScreen
{
   public MyScreen() {
      getMainManager().setBackground(
        BackgroundFactory.createBitmapBackground(
          Bitmap.getBitmapResource("background.jpg")));
   }
}


When you added the resource to the res folder, did you perform a refresh of the project in Eclipse? If it doesn't 'see' it, the packager ignores it. If you restarted Eclipse, it would pick it up the next time, which might explain why it started working randomly.


This should be the code to load your image, without any directory in the path.

Bitmap.getBitmapResource("background.jpg")

Then put the image in any package of your src directory like in

com.rim.sample.resources


When you say it failed what do you mean? Does it throw an error?

I've found that when I add/change a resource it might not take affect immediately. What I found I need to do is to delete the cod file and run a clean on the project (not just build it), then run the packaging (rapc) command. This should make sure the image is there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜