Android: getting Drawable from a URL not working on .jpg only works for .png

I am working on an Android application that pulls an image from a web page (specifically xckd.com). I work perfectly with this code of this basic form (see below)

ImageView iv = new ImageView;
    URL url = new URL(address);
    InputStream content = (InputStream)url.getContent();
    Drawable d = Drawable.createFromStream(content , "src"); 
    iv.setImageDrawable(d)

I noticed that when I was looking through some of my old comics, the image didn’t show (but I was correctly looking for other information from the page, so I know that the URL is correct). I decided that this result only occurs when the image is a .jpg file, but works fine when it is .png

I have googled around a lot and I can’t understand why this is so, is there a simple solution for this?

+3
source share
1 answer

Source: https://habr.com/ru/post/1779661/


All Articles