读图片

//读图片URL

URLuri=new URL("http://10.1.5.42:8080/ru.png");

HttpURLConnectionconnection = (HttpURLConnection) uri.openConnection();

connection.setConnectTimeout(5000);

connection.setRequestMethod("GET");

connection.setReadTimeout(5000);

connection.connect();

int code = connection.getResponseCode();

if(code==200){

InputStream inputStream = connection.getInputStream();

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

}

 

//读图片HttpClient

Path:图片的网址;

HttpClientclient=new DefaultHttpClient();

      

       HttpPost httpPost=new HttpPost(path);

 

       try {

              HttpResponse httpResponse =client.execute(httpPost);

              //得到实体数据

              HttpEntity entity =httpResponse.getEntity();

              //从实体里获得

              InputStream inputStream =entity.getContent();

             

              //把流转成bitmap

              final Bitmap bitmap =BitmapFactory.decodeStream(inputStream);

 

              runOnUiThread(new Runnable() {

                    

                     @Override

                     public void run() {

                            imageView.setImageBitmap(bitmap);

                           

                     }

             

//读图片HttpClient导包

 

<com.loopj.android.image.SmartImageView

        android:id="@+id/imageView"

        android:layout_width="100dp"

        android:layout_height="100dp"/>

 

    SmartImageView    imageView= (SmartImageView)convertView.findViewById(R.id.imageView);

 

imageView.setImageUrl(list.get(position).pic);

 

 

//读图片导包Utils

BitmapUtils bitmap=new BitmapUtils(context);

bitmap.display(imageview, str[position]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值