关闭

读图片

22人阅读 评论(0) 收藏 举报

//读图片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]);

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1368次
    • 积分:314
    • 等级:
    • 排名:千里之外
    • 原创:31篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档