BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-19-2007, 04:04 AM   #1 (permalink)
New Member
 
Join Date: Dec 2007
Model: 7100T
PIN: N/A
Carrier: GPRS
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying an image on the screen

Please Login to Remove!

Hi All,

I need to display an image on the screen. This is what i am doing

Bitmap img = Bitmap.getBitmapResource("/image.png");
BitmapField bf = new BitmapField(img, BitmapField.FOCUSABLE);
add(bf);

My project is at created at C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1\bin.

My jar file and image are in the same folder.

From the BlackBerry JDE i have added the image to the project. still it shows file not found.


where do i need to place the image in my project?

Please help.
Offline  
Old 12-19-2007, 07:11 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

See at getResourceAsStream() method of java.lang.Class in the RIM Device Java Library. In my project (i am using eclipse) my source code and my resources are compiled through ant build in one folder so that the main class of the application is in the same folder with the images. I use a code like this:
Code:
  private static byte[] readResourceBytes(String resourceName) {
    try {
      InputStream is = Class.forName(MAIN_CLASS).getResourceAsStream(
          resourceName);
      int length = is.available();
      byte[] resourceBytes = new byte[length];
      is.read(resourceBytes);
      return resourceBytes;
    } catch (Exception exc) {
    }
    return null;
  }

//load the image like this:

byte[] imageBytes = readResourceBytes(imageName);
EncodedImage image = EncodedImage.createEncodedImage(imageBytes, 0,
            imageBytes.length);
Good luck !
Offline  
Old 12-19-2007, 07:40 AM   #3 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

getBitmapResource should work. Try it without the backslash
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.