如何从网站获取特定图像并在Android应用程序中显示它们?
给定一个网站的URL,我想检索该网站的徽标和背景图像,并将其显示在android应用程序中。例如,从我想要的背景图像和黑客西部标志如何从网站获取特定图像并在Android应用程序中显示它们?,android,image,url,web,extract,Android,Image,Url,Web,Extract,给定一个网站的URL,我想检索该网站的徽标和背景图像,并将其显示在android应用程序中。例如,从我想要的背景图像和黑客西部标志 编辑:我忘了提到我正在尝试为运行时之前大小不确定的URL列表实现此效果使用此AsyncTask从URL public class LoadImageTask extends AsyncTask<Void, Void, Void>{ private Bitmap mMyBitmap; @Override protected Voi
编辑:我忘了提到我正在尝试为运行时之前大小不确定的URL列表实现此效果使用此
AsyncTask
从URL
public class LoadImageTask extends AsyncTask<Void, Void, Void>{
private Bitmap mMyBitmap;
@Override
protected Void doInBackground(Void... params) {
try {
URL url = new URL("https://hackwestern.com/images/logo_vert_spons.png");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
mMyBitmap = BitmapFactory.decodeStream(input);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mImageView.setImageBitmap(mMyBitmap);
}
}
嘿,谢谢你的回复!我现在了解了如何检索图像,但是是否有可能在不单独检索的情况下检索事件列表中的图像?我还没有找到从网站检索图像的方法,因为我一直在尝试获取url列表中大小不确定的图像。
new LoadImageTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);