任何人都可以告诉我为什么即使我从服务器上获取它也不会创建Bitmap?我看了至少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 :(得分:0)
InputStream in = new java.net.URL("your URL as a String").openStream();
Bitmap bmp = BitmapFactory.decodeStream(in);