知道图片的网络地址赋值给bitmap

知道图片的网络地址赋值给bitmap_第1张图片
image.png
new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        URL url = new URL("https://c-ssl.duitang.com/uploads/item/201904/22/20190422193309_y44wV.jpeg");
                        InputStream inputStream = url.openStream();
                        Bitmap bitmap =  BitmapFactory.decodeStream(inputStream);
                        Message message = handler.obtainMessage(0X1,bitmap);
                        handler.sendMessage(message);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            }).start();
 @SuppressLint("HandlerLeak")
        Handler handler =new Handler(){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                imageView.setImageBitmap((Bitmap) msg.obj);
            }
        };

你可能感兴趣的:(知道图片的网络地址赋值给bitmap)