android: webservice image replace with images in Local folder

后端 未结 2 466
盖世英雄少女心
盖世英雄少女心 2021-01-16 18:46

I am into final stage of chat application in android.

I am facing few issues while working with images and web service.

So when i select the image and sent

2条回答
  •  借酒劲吻你
    2021-01-16 19:07

    Use this method:

    public static Bitmap getBitmapFromURL(String src) {
            try {
                URL url = new URL(src);
                HttpURLConnection connection = (HttpURLConnection) url
                .openConnection();
                connection.setDoInput(true);
                connection.connect();
                connection.setReadTimeout(120000);
                InputStream input = connection.getInputStream();
                Bitmap myBitmap = BitmapFactory.decodeStream(input);
                return myBitmap;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    

    Here You need to pass the URL of the image to the function and you can set the image as setImageBitmap function.

提交回复
热议问题