从网站提取图像
答
Bitmap bmImg;
void downloadfile(String fileurl,ImageView img)
{
URL myfileurl =null;
try
{
myfileurl= new URL(fileurl);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
try
{
HttpURLConnection conn= (HttpURLConnection)myfileurl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
int[] bitmapData =new int[length];
byte[] bitmapData2 =new byte[length];
InputStream is = conn.getInputStream();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize =
bmImg = BitmapFactory.decodeStream(is,null,options);
img.setImageBitmap(bmImg);
//dialog.dismiss();
}
catch(IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
// Toast.makeText(PhotoRating.this, "Connection Problem. Try Again.", Toast.LENGTH_SHORT).show();
}
}
试试这个
答
下面的代码可以帮助你获取图像。如果你传递图像的网址。
public Drawable loadImageFromWebOperations(String url)
{
try
{
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGetRequest = new HttpGet(url);
HttpResponse response = client.execute(httpGetRequest);
InputStream is = response.getEntity().getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
该代码将返回您可以在ImageView的
imageView.setImageDrawable(d);
显示您可以将一个ImageView的添加到列表中的每一行,并设置可绘制的可绘制。