Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'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
like image 780
Casebash Avatar asked Mar 03 '10 03:03

Casebash


2 Answers

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")));
   }
}
like image 188
Skrud Avatar answered Oct 16 '22 17:10

Skrud


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.

like image 44
Andrew Avatar answered Oct 16 '22 17:10

Andrew