BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-19-2007, 05: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, 08: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, 08: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

Allen Bradley 1785ME16 Ser. A 16K 1785-ME16 Memory Cartridge
$98.0
Allen Bradley 1785ME16 Ser. A 16K 1785-ME16 Memory Cartridge picture2PCS Precision RTC Module AT24C32 DS3231 IIC Module Memory Module for Arduino
$2.87
2PCS Precision RTC Module AT24C32 DS3231 IIC Module Memory Module for Arduino pictureCAS Optional Expanded Memory For CL-5000
$15.0
CAS Optional Expanded Memory For CL-5000 pictureSiemens Simatic S5 Memory Speicher Modul card 128KB RAM 6ES5377-0AB41
$850.0
Siemens Simatic S5 Memory Speicher Modul card 128KB RAM 6ES5377-0AB41 pictureOLED Fingertip Pulse Oximeter,Blood Oxygen Monitor,USB memory,SW,FDA, US Seller
$36.0
OLED Fingertip Pulse Oximeter,Blood Oxygen Monitor,USB memory,SW,FDA, US Seller picture






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