简体   繁体   中英

Downloaded images are not displayed on android devices with high resolution

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");
}

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM