2013-06-12 45 views
3

誰能告訴我爲什麼即使我從服務器獲取它的位圖也沒有創建?我看了至少15個這樣的問題,發現每一樣東西都差不多,但仍然無法找到解決方案。請嘗試一下你自己如果你可以。URL也給出。 程序中沒有錯誤。 由於位圖沒有創建

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost("http://ademoproject.appspot.com/retrievedetails"); 

List<NameValuePair> list = new ArrayList<NameValuePair>(); 
list.add(new BasicNameValuePair("username",username)); 
UrlEncodedFormEntity urlencodedformentity = new UrlEncodedFormEntity(list); 

httppost.setEntity(urlencodedformentity); 
HttpResponse response = httpclient.execute(httppost); 
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 

Toast.makeText(this,br.readLine(), Toast.LENGTH_LONG).show(); 

byte []image=Base64.decode(br.readLine(), Base64.DEFAULT); 

Bitmap bm = BitmapFactory.decodeByteArray(image, 0, image.length); 

img.setImageBitmap(bm); 
+0

月[此](http://stackoverflow.com/questions/15850772/how-to-convert-a-google-charts-graph-to-image-in-android/ 15850907#15850907)回答幫助你。 – Gunaseelan

+0

不能正常工作。Imageview仍然沒有變化。 –

回答

0
InputStream in = new java.net.URL("your URL as a String").openStream(); 
Bitmap bmp = BitmapFactory.decodeStream(in); 
+0

我也必須發送一些數據到服務器(用戶名,在問題中指定)。但爲什麼HttpClient不工作 –