============ 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