Widziałem to pytanie: android how to download an 1mb image file and set to ImageView
To nie rozwiąże mój problem, jak to tylko pokazuje jak wyświetlić bitmapę po już masz go.Pobierz obraz ImageView na Androida
Próbuję pobrać obraz z adresu URL, aby był wyświetlany z obrazem na urządzeniu z systemem Android. Nie jestem pewien, jak to zrobić.
Mam rozejrzał się trochę w Internecie, jest to kod mam tak daleko:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Set local image
ImageView image = (ImageView) findViewById(R.id.test_image);
image.setImageResource(R.drawable.test2);
//Prepare to download image
URL url;
InputStream in;
//BufferedInputStream buf;
try {
url = new URL("http://i.imgur.com/CQzlM.jpg");
in = url.openStream();
out = new BufferedOutputStream(new FileOutputStream("testImage.jpg"));
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
out.close();
in.close();
buf = new BufferedInputStream(in);
Bitmap bMap = BitmapFactory.decodeStream(buf);
image.setImageBitmap(bMap);
if (in != null) {
in.close();
}
if (buf != null) {
buf.close();
}
} catch (Exception e) {
Log.e("Error reading file", e.toString());
}
}
Jeśli znalazłeś odpowiedź, ty powinien to zaakceptować. W ten sposób inni użytkownicy wiedzą, że to działa. Powodzenia! – Entreco