从图像Web使用setImageBitmap的AsyncTask的ImageView [英] AsyncTask ImageView from image web using setImageBitmap
本文介绍了从图像Web使用setImageBitmap的AsyncTask的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题在我的互联网显示此图像。 我不知道如何使它发挥作用。 我是新来的机器人。
的问题是,部分...
imView =(ImageView的)findViewById(R.id.imageView1);
imView.setImageBitmap(BM); //错误
感谢你。
我的code
公共类CarregaImagem扩展的AsyncTask<字符串,太虚,字符串> {
字符串IMAGEURL =http://www.cuboweb.com.br/android/images/logoconsulfarma.png;
私人ProgressDialog进展情况;
私人活动的活动;
位图bmImg;
公共CarregaImagem(活动活动){
this.activity =活动;
}
在preExecute保护无效(){
进度=新ProgressDialog(活动);
progress.setTitle(Aguarde ......);
progress.setMessage(Carregando ......);
progress.show();
}
保护字符串doInBackground(字符串... PARAMS){
// TODO自动生成方法存根
尝试 {
URL aURL =新的URL(IMAGEURL);
最后的URLConnection康恩= aURL.openConnection();
conn.connect();
最后的BufferedInputStream双=新的BufferedInputStream(conn.getInputStream());
最后的位图BM = BitmapFactory.de codeStream(之二);
BitmapFactory.de codeStream(新的URL(IMAGEURL).openConnection()的getInputStream());
bis.close();
}赶上(IOException异常E){
IMAGEURL =;
}赶上(例外F){
IMAGEURL =;
}
返回IMAGEURL;
}
保护无效onPostExecute(字符串IMAGEURL){
如果(!imageUrl.equals()){
imView =(ImageView的)findViewById(R.id.imageView1);
imView.setImageBitmap(BM); //错误
} 其他{
Toast.makeText(活动,NAO FOIpossívelobter resultados,Toast.LENGTH_LONG).show();
}
progress.dismiss();
}
}
解决方案
您创建doInBackground位图,你永远不会使用。 返回代替该位图,它用在onPostExecute
I have a problem to display this image in my internet. I have no idea how to make it work. I am new to android.
The problem is that part ...
imView = (ImageView) findViewById(R.id.imageView1);
imView.setImageBitmap(bm); //error
Thank you.
my code
public class CarregaImagem extends AsyncTask<String, Void, String>{
String imageUrl = "http://www.cuboweb.com.br/android/images/logoconsulfarma.png";
private ProgressDialog progress;
private Activity activity;
Bitmap bmImg;
public CarregaImagem(Activity activity){
this.activity = activity;
}
protected void onPreExecute() {
progress = new ProgressDialog(activity);
progress.setTitle("Aguarde...");
progress.setMessage("Carregando...");
progress.show();
}
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try {
URL aURL = new URL(imageUrl);
final URLConnection conn = aURL.openConnection();
conn.connect();
final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
final Bitmap bm = BitmapFactory.decodeStream(bis);
BitmapFactory.decodeStream(new URL(imageUrl).openConnection().getInputStream());
bis.close();
} catch (IOException e) {
imageUrl = "";
} catch(Exception f){
imageUrl = "";
}
return imageUrl;
}
protected void onPostExecute(String imageUrl) {
if(!imageUrl.equals("")){
imView = (ImageView) findViewById(R.id.imageView1);
imView.setImageBitmap(bm); //error
} else{
Toast.makeText(activity, "Não foi possível obter resultados", Toast.LENGTH_LONG).show();
}
progress.dismiss();
}
}
解决方案
You create a bitmap in doInBackground that you never use. Return instead the bitmap and use it in onPostExecute.
这篇关于从图像Web使用setImageBitmap的AsyncTask的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文