Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad Image from Image URL taking so much time to display
    primarykey
    data
    text
    <p>I used the code from the following link: <a href="http://rincethomas.blogspot.in/2012/04/display-image-from-url-in-bb.html"><strong>Signare's Blog</strong></a>. I have 10 image URLs and would like to retrieve and show them on my screen. When I use the code from the above link, it's taking more than 10 minutes to load all of the images. How do I speed up this loading?</p> <pre><code>URLBitmapField post_img= new URLBitmapField(image_url); add(post_img); </code></pre> <p>where the class <code>URLBitmapField</code> is defined as:</p> <pre><code>import net.rim.device.api.math.Fixed32; import net.rim.device.api.system.Bitmap; import net.rim.device.api.system.EncodedImage; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.BitmapField; public class URLBitmapField extends BitmapField implements URLDataCallback { EncodedImage result = null; public static EncodedImage _encoded_img = null; int _imgWidth = 52; int _imgHeight = 62; int _imgMargin = 10; public URLBitmapField(String url) { try { http_image_data_extrator.getWebData(url, this); } catch (Exception e) {} } public Bitmap getBitmap() { if (_encoded_img == null) return null; return _encoded_img.getBitmap(); } public void callback(final String data) { if (data.startsWith("Exception")) return; try { byte[] dataArray = data.getBytes(); _encoded_img = EncodedImage.createEncodedImage(dataArray, 0, dataArray.length); // with scale _encoded_img = sizeImage(_encoded_img, _imgWidth, _imgHeight); setImage(_encoded_img); UiApplication.getUiApplication().getActiveScreen().invalidate(); } catch (final Exception e){} } public EncodedImage sizeImage(EncodedImage image, int width, int height) { int currentWidthFixed32 = Fixed32.toFP(image.getWidth()); int currentHeightFixed32 = Fixed32.toFP(image.getHeight()); int requiredWidthFixed32 = Fixed32.toFP(width); int requiredHeightFixed32 = Fixed32.toFP(height); int scaleXFixed32 = Fixed32.div(currentWidthFixed32,requiredWidthFixed32); int scaleYFixed32 = Fixed32.div(currentHeightFixed32,requiredHeightFixed32); result = image.scaleImage32(scaleXFixed32, scaleYFixed32); return result; } } public interface URLDataCallback { public void callback(String data); } </code></pre> <p>and the class <code>http_image_data_extrator</code> is defined as:</p> <pre><code>import java.io.IOException; import java.io.InputStream; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import net.rim.device.api.system.RadioInfo; import net.rim.device.api.system.WLANInfo; import net.rim.device.api.ui.UiApplication; public class http_image_data_extrator { static String url_=""; static StringBuffer rawResponse=null; public static void getWebData(String url, final URLDataCallback callback) throws IOException { HttpConnection connection = null; InputStream inputStream = null; try { if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)&amp;&amp; RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) { url += ";interface=wifi"; } connection = (HttpConnection) Connector.open(url, Connector.READ, true); String location=connection.getHeaderField("location"); if(location!=null){ if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)&amp;&amp; RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) { location += ";interface=wifi"; } connection = (HttpConnection) Connector.open(location, Connector.READ, true); }else{ connection = (HttpConnection) Connector.open(url, Connector.READ, true); } inputStream = connection.openInputStream(); byte[] responseData = new byte[10000]; int length = 0; rawResponse = new StringBuffer(); while (-1 != (length = inputStream.read(responseData))) { rawResponse.append(new String(responseData, 0, length)); } int responseCode = connection.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK){ throw new IOException("HTTP response code: "+ responseCode); } final String result = rawResponse.toString(); UiApplication.getUiApplication().invokeLater(new Runnable() { public void run(){ callback.callback(result); } }); } catch (final Exception ex) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { callback.callback("Exception (" + ex.getClass() + "): " + ex.getMessage()); } }); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload