Android - Function to convert ImageURL to Bitmap object - ANDROID - Helper

Monday, September 05, 2011

Android - Function to convert ImageURL to Bitmap object


IMAGE URL TO BITMAP

Use this function “convertURLtoBitmap”

public Bitmap convertURLtoBitmap(String src) {

                try {

                                URL url = new URL(src);
                                               
                                HttpURLConnection connection = (HttpURLConnection) url
                                                .openConnection();

                                connection.setDoInput(true);
                                connection.connect();

                                InputStream input = connection.getInputStream();
                                Bitmap myBitmap = BitmapFactory.decodeStream(input);

                                return myBitmap;

                }

                catch (IOException e) {

                                e.printStackTrace();
                                return null;

                }
}

No comments:

Post a Comment