1

I have this code that works with an image in the drawable resource and was wandering how I would rewrite it for an url image:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MultiTouchActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);

        TouchImageView img = new TouchImageView(this);
        img.setImageResource(R.map);
        img.setMaxZoom(6f);
        setContentView(img);
    }
}
cinci-hal
  • 11
  • 4

1 Answers1

1

You'll have to download the remote image yourself.

You could do it manually:

new AsyncTask {
    Bitmap doInBackground(Void[] params) {
        InputStream in = new java.net.URL(image_url).openStream();
        return BitmapFactory.decodeStream(in);
    };

   void onPostExecute(Bitmap bmp) {
       imageView.setImageBitmap(bmp);           }
   }
}.execute();

Or use Picasso and get the benefit of simplicity and local caching:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Other libs that do a decent job in downloading and caching remote images:

Gilad Haimov
  • 5,767
  • 2
  • 26
  • 30