0

I am using a method to get the Image from URL when a button is clicked but it gets too much time, about 4-5 seconds to show an image sized only 6 kb using 3G not wi-fi.

My method is this;

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

and then;

 Bitmap bimage = getBitmapFromURL("http://www.replikler.net/test2.jpg"); ImageView image = (ImageView)findViewById(R.id.movie_image); image.setImageBitmap(bimage); 

do you know another way (faster) to get an image from url ?

1
  • Be sure you execute network operations in another thread, by using AsyncTask for example Commented Jul 11, 2012 at 21:12

1 Answer 1

2
imageView.setImageDrawable(Drawable.createFromStream((InputStream)new URL(url).getContent(), "src")); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.