title: Convert image URL to drawable resource id in android
body: <p>I'm using the <a href="https://github.com/flavioarfaria/KenBurnsView" rel="nofollow">KenBurnsView</a> library with this code:</p>
  
  <pre><code>mHeaderPicture.setResourceIds(R.drawable.picture0, R.drawable.picture1);
  </code></pre>
  
  <p>As you can see it takes drawable resource ids.</p>
  
  <p>What I want to do is covert all photos URLS to drawable resource ids.
  Photo urls like this:</p>
  
  <pre><code>http://example.com/image.jpg
  http://example.com/image2.jpg
  http://example.com/image3.jpg
  http://example.com/image4.jpg
  </code></pre>
  
  <p>I tried this code here and it didn't work:</p>
  
  <pre><code>Bitmap drawable_from_url(String url) throws java.net.MalformedURLException, java.io.IOException {
      Bitmap x;
  
      HttpURLConnection connection = (HttpURLConnection)new URL(url) .openConnection();
      connection.setRequestProperty("User-agent","Mozilla/4.0");
  
      connection.connect();
      InputStream input = connection.getInputStream();
  
      x = BitmapFactory.decodeStream(input);
      return x;
  }
  </code></pre>
  
  <p>I have read a LOT of questions and answers all over the web and I didn't find a good tutorial or solution.</p>