Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I wrote this code to reproduce the error:</p> <pre><code>LinearLayout ll = (LinearLayout) findViewById(R.id.root); try { ImageView image = new ImageView(this); Bitmap bitmap = BitmapFactory.decodeStream(getAssets().open("tag-logo-android.png")); image.setImageBitmap(bitmap); ll.addView(image); image = new ImageView(this); Drawable drawable = Drawable.createFromStream(new URL("http://cdn.sstatic.net/stackoverflow/img/tag-logo-android.png").openStream(), null); image.setImageDrawable(drawable); ll.addView(image); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>The problem isn't the source of the image. The problem is that <code>Drawable</code> ignores screen density. This code works:</p> <pre><code>LinearLayout ll = (LinearLayout) findViewById(R.id.root); try { ImageView image = new ImageView(this); Bitmap bitmap = BitmapFactory.decodeStream(getAssets().open("tag-logo-android.png")); image.setImageBitmap(bitmap); ll.addView(image); image = new ImageView(this); bitmap = BitmapFactory.decodeStream(new URL("http://cdn.sstatic.net/stackoverflow/img/tag-logo-android.png").openStream()); image.setImageBitmap(bitmap); ll.addView(image); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>In your case you can use:</p> <pre><code>bitmap = BitmapFactory.decodeFile(new File(Environment.getExternalStorageDirectory(), "test.png")) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload