如何从URL加载图像中balckberry

问题描述:

可能重复:
Show Images from URL in blackberry如何从URL加载图像中balckberry

嗨想从URL中balckberry直接LAOD的图像。 balckberry没有选择直接打电话。是那里做的,所以引导我。

+0

检查我这个问题的答案-http://stackoverflow.com/questions/12049101/show-images-from-url-in-blackberry/12049139#12049139 – Signare

+0

海感谢您的代码它只是工作真棒,但我怎么会把这个位图image.thanks。 – Pramodhini

+0

如果它的有用,然后upvote它..... – Signare

没有捷径可以这样做。 你需要通过代码来完成。

public static InputStream getInputStream(String url) 
{ 
    InputStream inputStream = null; 
    HttpConnection httpConnection = null; 
    try 
    {       
     httpConnection = (HttpConnection)Connector.open(url+connectiontype)); 
     httpConnection.setRequestMethod(HttpConnection.POST); 
     final int r=httpConnection.getResponseCode(); 
     if(r==200) 
      inputStream = httpConnection.openDataInputStream(); 
    } 
    catch(final Exception e) 
    { 
     System.out.println("Error is "+e.getMessage()); 
    } 
    return inputStream; 
} 

,并使用getInputStream()这样的:

InputStream is=getInputStream(s1); 
int length=is.available(); 
//System.out.print("length ==========="+length);   
byte[] data=new byte[length]; 

data = IOUtilities.streamToBytes(is); 

// code to save image in sd card 
saveFile.create(); 
OutputStream outStream = saveFile.openOutputStream(); 
outStream.write(data); 
outStream.close(); 
saveFile.close(); 
is.close(); 

此代码将保存从URL的形象。

+0

你ok.fine和不介意我是否做错了什么。谢谢 – Pramodhini