Android: How to download a .png file using Async and set it to ImageView? -
Let me know one. The URL of the PNG image is found, which needs to be downloaded and set as the source of an image view. I am making a beginning so far, so there are some things that I do not understand: 1) Where should I store the file? 2) How do I set up ImageView in Java code? 3) How can correctly override asyncTask methods?
Thank you in advance, would appreciate any help.
I'm not sure that you can create a png from the explanation download However, here I download the images First time, you download the image:
protected static byte [] imageByter (reference CTX, string Strurl) {try {url = url = new URL (urlContactIcon + strurl); InputStream = (InputStream) url.getContent (); Byte [] buffer = new byte [8192]; Int bytes read; Bytereon OutputStream Output = New Bytereanputstream (); While ((Bytes Reid = Reid (buffer))! = -1) {Output. Written (buffer, 0, bytes read); } Return output. To Batere (); } Catch (malmarmdureleuxation E) {e.printStackTrace (); Return tap; } Hold (IOException e) {e.printStackTrace (); Return tap; }}
And then, create a bitmap and add it to the image view:
bytes = ebayl (this, MULL); BM = BitmapFranet Decodbitearrere (bytes, 0, bytes length); YourImageview.setImageBitmap (BM);
And so is it.
Edit
Actually, you can save the file by doing this:
> file file = new file (filename) ; FileOutputStream fos = New FileOutputStream (file); Fos.write (Imagery (this, MULL)); Fos.close ();
Comments
Post a Comment