BitmapFactory / compress() ForceClose with specific images

All your problems with Audio, Video and Images.

BitmapFactory / compress() ForceClose with specific images

Postby nioupy » Tue Aug 03, 2010 4:34 am

Hi,

I am currently running a code that downloads and saves images from the web on the SDCard :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     private void DownloadMyImage(String src , String dest) {
  2.        
  3.         File dir = new File(Environment.getExternalStorageDirectory() + "/kaldata");
  4.         if(!dir.exists() )
  5.             dir.mkdirs();        
  6.        
  7.                 InputStream is = null;
  8.                 File f = new File(dest);
  9.  
  10.                 try {
  11.                         is = (InputStream) new URL(src).getContent();
  12.                         BufferedInputStream bis = new BufferedInputStream(is);
  13.                         Bitmap bm = BitmapFactory.decodeStream(bis);
  14.                         FileOutputStream fos = null;
  15.                         try {
  16.                                 fos = new FileOutputStream(f);
  17.                         } catch (FileNotFoundException e) {
  18.                                 ShowError("DownloadMyImage", e.toString() + " [" + src +"]");
  19.                         }
  20. ShowError("bf bmcompress", "bm.compress " + src);                      
  21.                         bm.compress(Bitmap.CompressFormat.JPEG, 100, fos);
  22. ShowError("af bmcompress", "bm.compress " + src);                      
  23.                         fos.flush();
  24.                         fos.close();
  25.                        
  26.                 } catch (MalformedURLException e) {
  27.                         ShowError("DownloadMyImage", e.toString() + " [" + src +"]");
  28.                 } catch (IOException e) {
  29.                         ShowError("DownloadMyImage", e.toString() + " [" + src +"]");
  30.                 }              
  31.         }
  32.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The function above works pretty well, and most of my images are downloaded correctly. However, sometimes, I got some FC that took me loooong time to trace in my code: basically it happens when doing the bm.compress() call.
An example of a bug leading image is here : http://www.kaldata.com/images/news/logos/android.jpg

Does anyone has an idea of how to solve this?

Thanks in advance for any lead :)
nioupy
Developer
Developer
 
Posts: 36
Joined: Sat Apr 03, 2010 1:34 pm

Top

Re: BitmapFactory / compress() ForceClose with specific imag

Postby nioupy » Tue Aug 03, 2010 5:05 am

ok, guess i'm on the right track [and stoopid sometimes] : a little "if(bm != null)" before the buggy line saves me the "ForceClose"

Now, my next steps will be finding out why this bm would be null ;)
nioupy
Developer
Developer
 
Posts: 36
Joined: Sat Apr 03, 2010 1:34 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests