即時通訊嘗試在我的應用程序中顯示來自url的圖像。但是我使用的方法很長。 這個代碼我建立在計算器在10-12秒加載從URL到可繪製或位圖的圖像:最好和最快的方式
public Bitmap getImage(String url,String src_name) throws java.net.MalformedURLException, java.io.IOException {
Bitmap bitmap;
HttpURLConnection connection = (HttpURLConnection)new URL(url) .openConnection();
connection.setRequestProperty("User-agent","Mozilla/4.0");
connection.connect();
InputStream input= connection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
return bitmap;
}
10張圖像。如果使用此代碼。
和
///==========================================================================================================================================
public Drawable getImage(String url, String src_name) throws java.net.MalformedURLException, java.io.IOException
{
Drawable abc =Drawable.createFromStream(((java.io.InputStream)new java.net.URL(url).getContent()), src_name);
return abc;
}
如果使用此代碼 - 圖像中9-11秒加載。 圖像不大。最大寬度或高度是400-450。 ofcourse我告訴這個循環中的這個功能是這樣的:for (int i =0;i<10;i++){image[i]=getImage(url);}
任何能告訴如何最好的和緊固顯示圖像在我的應用程序? 問候,彼得。