zoukankan      html  css  js  c++  java
  • android 异步图片处理 工具类


    工具代码


     public class AsyncUploadImage extends AsyncTask<Object, Object, Object> {
    	private static final String TAG = "AsyncUploadImage ";
    	ImageView iv;
    	private HttpURLConnection connection;
    	private InputStream is;
    	private Bitmap bitmap;
    	public AsyncUploadImage(ImageView mImageView) {
    		iv = mImageView;
    	}
    	@Override
    	protected Object doInBackground(Object... params) {
    		URL url;
    		try {
    			url = new URL((String) params[0]);
    			connection = (HttpURLConnection) url.openConnection();
    			connection.setDoInput(true);
    			connection.connect();
    			is = connection.getInputStream();
    			bitmap = BitmapFactory.decodeStream(is);
    			is.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				if (is != null) {
    					is.close();
    				}
    				if (connection != null) {
    					connection.disconnect();
    				}
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    		}
    		return bitmap;
    	}
    	@Override
    	protected void onPostExecute(Object result) {
    		super.onPostExecute(result);
    		if (null != result) {
    			iv.setImageBitmap((Bitmap) result);
    			Log.i(TAG, "image download ok!!!");
    		}else {
    			iv.setBackgroundResource(R.drawable.shuben1);
    			Log.i(TAG, "image download false!!!");
    		}
    	}
    
    }

    具体使用的代码

     new AsyncUploadImage(itemIcon).execute("http://temp/file/book/images/1325310017.jpg");
    
    //http://temp/file/book/images/1325310017.jpg  -> (this is your image url..)





  • 相关阅读:
    泛型的运用
    LinkdList和ArrayList异同、实现自定义栈
    MD5文件去重
    mysql协议解析
    solrconfig.xml主要配置项
    自定义特性使用
    使用OWIN 为WebAPI 宿主 跨平台
    Web.config配置文件详解
    IIS 之 在IIS7、IIS7.5中应用程序池最优配置方案
    GitHub 创建工程
  • 原文地址:https://www.cnblogs.com/flyingsir/p/3983771.html
Copyright © 2011-2022 走看看