0

Downloaded images are not displayed on devices with resolution higher than 1280x720. I tried different DPI of images. How to resolve this? Thanks in advance. I use such code:

public class ViewActivity extends Activity {

private TextView txtUrl;
private ImageView imgView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Веб-адрес картинки
    String url = "http://somesite.com/images/picture.jpg";
    txtUrl = (TextView) findViewById(R.id.txtUrl);
    txtUrl.setText(url);

    imgView = (ImageView) findViewById(R.id.imgView);

    try {
        imgView.setImageDrawable(grabImageFromUrl(url));
    } catch (Exception e) {
        txtUrl.setText("Error: Exception");
    }
}

private Drawable grabImageFromUrl(String url) throws Exception {
    return Drawable.createFromStream(
            (InputStream) new URL(url).getContent(), "src");
}

}

1 Answers1

1

I think it's a OutOfMemory error. You have to resize image. Convert drawable to Bitmap

Bitmap bitmap = ((BitmapDrawable)grabImageFromUrl(url)).getBitmap();

and resize using this solution:

Resizing a Bitmap

Community
  • 1
  • 1
pablogupi
  • 774
  • 11
  • 27