Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:18:11+00:00 2026-06-02T22:18:11+00:00

This is code i am using to fetch image form url but i am

  • 0

This is code i am using to fetch image form url but i am getting blanck screen please help.
Code For HttpConnection:

StringBuffer raw = new StringBuffer();
    HttpConnection _c = null;
    InputStream _is = null;
    try 
    {
        _c = (HttpConnection)Connector.open(url);
        _c.getHeaderField("Location");          
        int rc = _c.getResponseCode();                      
        if (rc != HttpConnection.HTTP_OK) 
        {
            throw new IOException("HTTP response code: " + rc);
        }           
        _is = _c.openInputStream();

        _c.getType();
        int len = (int)_c.getLength();
        {

            data = new byte[256];            
            int size = 0;
            while ( -1 != (len = _is.read(data)) ) 
            {
                raw.append(new String(data, 0, len));
                size += len;
            }
            String retVal = raw.toString();
            // .alert(retVal);
            return retVal+"URL is"+url;
        }
    } 
    catch (Exception e) 
    {
        throw new IllegalArgumentException("Not an HTTP URL");
    }
    finally 
    {        
        if (_is != null)
            _is.close();
        if (_c != null)
         _c.close();
    }

Code to get Image from perticuler URL:

 public static Bitmap getImage(String url)
 {

     Bitmap bitmap;
     EncodedImage bmp = EncodedImage.createEncodedImage(data, 0, data.length);
     bitmap=bmp.getBitmap();
     return bitmap;
}

Following code i am using to display image on MainScreen:

Bitmap bt=HttpUtils.getImage("http://www.eng.chula.ac.th/files/building.jpg");                  
        BitmapField bmp=new BitmapField(bt);
        bmp.setBitmap(bt);
        add(bmp);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:18:14+00:00Added an answer on June 2, 2026 at 10:18 pm

    Try this code –

    URLBitmapField post_img= new URLBitmapField(image_url);
    add(post_img);
    
    
    
    
    
    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();
    
            //bitmap = EncodedImage.createEncodedImage(dataArray, 0, dataArray.length);//no scale
    
            _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);
    
    }
    
    
    
    
    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;
        //static String result = null;
             public static void getWebData(String url, final URLDataCallback callback) throws IOException {
                 //url_=url;
    
                     HttpConnection connection = null;  
                     InputStream inputStream = null;  
    
                    try {  
    
    
                        if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
                                && 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)
                                    && 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());  
                            }  
                        });  
                    }
        }  
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to display image from URL, but it is not
I'm using a messenger service to asynchronously fetch an image from a URL but
I use the following code to reload an image using jQuery: //Fetch image associated
I am using this code to display all the rows from database, but when
Im using the following code to fetch image from a file,create an image list
This code using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using System.Data.Entity.ModelConfiguration;
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I have this code :- using (System.Security.Cryptography.SHA256 sha2 = new System.Security.Cryptography.SHA256Managed()) { .. }
I found this code using Google. private int RandomNumber(int min, int max) { Random
I get an error when I compile this code: using System; public struct Vector2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.