JPEG not producing a Drawable when loading from web

All your problems with Audio, Video and Images.

JPEG not producing a Drawable when loading from web

Postby donEduard » Wed Aug 18, 2010 9:58 am

Hello everybody,

I encountered a strange problem. I am downloading poster thumbnails form TMDb.org in my app. All the images work perfect when I load them in the Android Browser or in Chrome/Firefox on the PC. But in my app, some pictures (always the same) result in a null Drawable when getting them from the web...
For example, http://hwcdn.themoviedb.org/posters/185/4bc96daf017a3c57fe032185/vampire-strangler-thumb.jpg works, http://hwcdn.themoviedb.org/posters/4fc/4c072eb4017a3c7e890004fc/entheogen-awakening-the-divine-within-thumb.jpg results in a null drawable.
There is no messag in the logs that creation failed or similar.

I attached a demo Eclipse project with some pics that work and don't work in the attachment. It is derived from the gallery example somewhere in this forum.

Thanks, donEduardo
Attachments
DownloadPicTrubles.zip
Eclipse project with the problem included. For example, picture 3 does not work.
(47.83 KiB) Downloaded 38 times
donEduard
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Aug 10, 2010 8:34 am
Location: Switzerland

Top

Re: JPEG not producing a Drawable when loading from web

Postby donEduard » Wed Aug 18, 2010 3:04 pm

Ok, sortet it out:

i found http://www.mail-archive.com/android-developers@googlegroups.com/msg87665.html... now it works. I replaced the commented out code with the one before it:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 /**
  2.                  * Returns a new ImageView to be displayed, depending on the position
  3.                  * passed.
  4.                  */
  5.                 public View getView(int position, View convertView, ViewGroup parent) {
  6.                         ImageView i = new ImageView(this.myContext);
  7.  
  8.                         try {
  9.                                 URL bitmapUrl = new URL(myRemoteImages[position]);
  10.                             HttpGet httpRequest = null;
  11.  
  12.                         try {
  13.                                 httpRequest = new HttpGet(bitmapUrl.toURI());
  14.                         } catch (URISyntaxException e) {
  15.                                 e.printStackTrace();
  16.                         }
  17.  
  18.                         HttpClient httpclient = new DefaultHttpClient();
  19.                         HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
  20.  
  21.                         HttpEntity entity = response.getEntity();
  22.                         BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
  23.                         InputStream instream = bufHttpEntity.getContent();
  24.                         Bitmap bm = BitmapFactory.decodeStream(instream);
  25. //
  26. //                              /* Open a new URL and get the InputStream to load data from it. */
  27. //                              URL aURL = new URL(myRemoteImages[position]);
  28. //                              URLConnection conn = aURL.openConnection();
  29. //                              conn.connect();
  30. //                              InputStream is = conn.getInputStream();
  31. //                              /* Buffered is always good for a performance plus. */
  32. //                              BufferedInputStream bis = new BufferedInputStream(is);
  33. //                              /* Decode url-data to a bitmap. */
  34. //                              Bitmap bm = BitmapFactory.decodeStream(bis);
  35. //                              bis.close();
  36. //                              is.close();
  37.                                 /* Apply the Bitmap to the ImageView that will be returned. */
  38.                                 i.setImageBitmap(bm);
  39.                         } catch (IOException e) {
  40.                                 i.setImageResource(R.drawable.icon);
  41.                                 Log.e("DEBUGTAG", "Remtoe Image Exception", e);
  42.                         }
  43.  
  44.                         /* Image should be scaled as width/height are set. */
  45.                         i.setScaleType(ImageView.ScaleType.FIT_CENTER);
  46.                         /* Set the Width/Height of the ImageView. */
  47.                         i.setLayoutParams(new Gallery.LayoutParams(150, 150));
  48.                         return i;
  49.                 }
  50.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
donEduard
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Aug 10, 2010 8:34 am
Location: Switzerland

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 12 guests