Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified
Accepted Solution

How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

I want to access an image stored in Blackberry, say at location "store/home/user/image.png" .

 

Now can i access this image as,

 

 

String filePath = "file:///store/home/user/image.png;
Bitmap image = Bitmap.getBitmapResource(filePath);
BitmapField bitmapField = new BitmapField(image, BitmapField.FOCUSABLE);

 

 

OR

 

I have to access it as,

 

 

String filePath = "file:///store/home/user/image.png;
  FileConnection fconn = (FileConnection)Connector.open(filePath, Connector.READ); 
  if (fconn.exists()) 
  {
                ........
                ........                           

     input.close();
     fconn.close();                            

  }

 

I am able to access the image using the second way but I want to know that can I access it using "Bitmap.getBitmapResource(filePath)" ?

 

 

Please use plain text.
Developer
aditya_BB
Posts: 26
Registered: ‎10-21-2009
My Device: Not Specified

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

You need to use File connection ...

 

 

---

Aditya

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

Thanks.. means I can only access that stored image using my second way (ie. opening the FileConnection, reading the image into byte[] & then converting the byte[]  toimage).

 

am i right?

 

 

 

 

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,189
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

getBitmapResource refers to a resource. this would be a bitmap that is part of your project. not a random bitmap on some filesystem.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
aditya_BB
Posts: 26
Registered: ‎10-21-2009
My Device: Not Specified

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

Yes.

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

[ Edited ]

Thanks Simon_hain,

 

Is there any other way than opening FileConnection to access that stored image on filesystem ? as I m accessing that image 2 times. so everytime I m opening FileConnection to read that image. So to avoid this extra overhead is there any other way ?

Please use plain text.
Developer
simon_hain
Posts: 16,189
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

after you have read the image you can reference it, of course. no need to read it again.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

ok . but for first time reading is there any way other than opening FileConnection ?

Please use plain text.
Developer
simon_hain
Posts: 16,189
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

no
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to access image stored in Blackberry using Bitmap.getBitmapResource() ?

ok. Thanks a lot..

Please use plain text.