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
Contributor
Ne0macer
Posts: 13
Registered: ‎06-11-2013
My Device: Blackberry 9300
My Carrier: Vodacom

Display image from URL on Blackberry screen

Hello.

 

I recently started creating a new app and I use quite a few images in it. The problem is, using so many images cause the app size to be rathr bigger than what I'd like it to be, so I was thinking that using a URL connection to these images to display them, instead of adding all of them in the res folder will save a lot of space. However, I am still very new to Java and Blackberry development.

 

I have searched around a lot on Google and other sites like Stackoverflow, but none of those answers actually helped me. So basically my question is, how do I display an image from a URL (ex. www.picbase.com/mylogo.jpg) unto my screen? And how can I use a indicator like the ActivityIndicator to actually show that my app is trying to load something in the background? Can anyone maybe provide me with some useful example code that I could use? It will be appreciated very much.

 

Thanks!

 

 

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

Re: Display image from URL on Blackberry screen

you would have to download the image first, displaying a web url directly is not supported.
see the httpdemo for a good start how to do that.

There is no (good) built-in indicator for something like that, so i would suggest taking a nice gif and displaying it in an animated state somewhere.
----------------------------------------------------------
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
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Display image from URL on Blackberry screen

[ Edited ]

Search the forum for "image URL" as there are many other Threads on this or similar topics. 

 

This is the closest thing to what you want that I have seen:

http://www.coderholic.com/blackberry-webbitmapfield/

 

However this code in itself has a number of things I don't like (for example, why convert to a String and then back to bytes), but it has the basics.  But even if you use this, if you have a page with loads of images you can run into errors with Threading, So for image processing like this you really need a Thread pool, and that all gets quite complicated.

 

Also of course, unless you 'cache' or store these images, each time the user runs your app, he or she downloads the images again.  For some apps of course, downloading them all the time is a requirement because they change. 

 

In your case, I suspect the images don't change, so I would consider a one off download, as part of the 'installation', then store the images on the SD Card.  If you think this is a good idea, then perhaps this sample will help:

http://supportforums.blackberry.com/t5/Java-Development/Unzip-zip-archive-with-sample-resource-insta...

 

Please use plain text.
Developer
alishaik786
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: Display image from URL on Blackberry screen

Check this STACKOVERFLOW Link

 

Bitmap Image not displaying from a URL link Blackberry

 

I think this one you are asking....!

 

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Display image from URL on Blackberry screen

The way it reads the bytes was one of the other things that I did not like about the link I posted previously.  However there are issues with the code supplied above too.  For example:

 

            is=connection.openInputStream();
           
int length=is.available();
           
byte[] data=newbyte[length];

            data
=IOUtilities.streamToBytes(is);

 

Should in fact just be:

 

            is=connection.openInputStream();
            data=IOUtilities.streamToBytes(is);

Downloading images on the fly is a nice idea in practice but has some significant issues.  So as I suggested, if you don't have to do it, don't. 

Please use plain text.