Charlie Charlie - 4 years ago 139
Android Question

Android: load images with zoom from URL

I am using to load my images with high resolution and zoom quality with the tutorial:

It uses images from

. How I could do to load images from a

Answer Source

The class SubsamplingScaleImageView has also a method to load an image that isn't from Assets:

SubsamplingScaleImageView.setImageFile(String extFile)

So you can get the image from the URL and save it on internal storage. Then you can load the image using the path from internal storage. To get the image as a Bitmap from an URL:

URL myFileUrl = new URL (StringURL);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();

InputStream is = conn.getInputStream();
Bitmap bm = BitmapFactory.decodeStream(is);

To save the Bitmap on internal storage:

FileOutputStream out = new FileOutputStream(context.getCacheDir() + filename);
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
// Don't forget to add a finally clause to close the stream


SubsamplingScaleImageView imageView =  (SubsamplingScaleImageView)findViewById(;
imageView.setImageFile(context.getCacheDir() + filename);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download