-2

可能重複:
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

回答

0

沒有捷徑可以這樣做。 你需要通過代碼來完成。

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
+0

你ok.fine和不介意我是否做錯了什麼。謝謝 – Pramodhini