Android Download Picture display problem

Source: Internet
Author: User

============ Problem Description ============


I downloaded the image from the server side with the following code and ran it in the new thread
System.out.println ("Before BM =" + BM); String IMAGEURL1 = "http://10.0.2.2:8080/BBStuServlet/test01_upload_1.jpg"; bm = Nettool.downlodbitmap (IMAGEURL1); Map2.put ("image", BM); SYSTEM.OUT.PRINTLN ("After BM =" + BM);

Output in Logcat: Before Bm=null and after BM = [email protected]
Then I set the image on the main line thread bitmap
Image.setimagebitmap (BM);

The Downloadbitmap () method is as follows:
/* * Download picture from the specified URL */public static Bitmap downlodbitmap (String url) {URL myfileurl = null; Bitmap Bitmap = null;try {myfileurl = new URL (URL),} catch (Malformedurlexception e) {//TODO auto-generated catch Blocke. Printstacktrace ();} try {HttpURLConnection conn = (httpurlconnection) myfileurl.openconnection (); Conn.setdoinput (true); Conn.connect (); I Nputstream is = Conn.getinputstream (), bitmap = Bitmapfactory.decodestream (is); Is.close (); catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}



But the image does not show the bitmap, which is why. Obviously has shown that the download is good, the picture in 135K, also is not big AH. What's going on, tangled up all day.

============ Solution 1============


Because you perform image.setimagebitmap (BM); When the picture is not downloaded well, you should send a message to the main thread after downloading it, and notify the main thread to display the picture.

============ Solution 2============


Update the main thread picture with handler, or use Asynctask to download the image asynchronously

Android Download Picture display problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.