Bitmap on sdcard & decodestream

All your problems with Audio, Video and Images.

Bitmap on sdcard & decodestream

Postby gh3 » Tue Sep 30, 2008 1:01 am

Hi,

thanks first of all to plusminus for the gr8 work with this forum and his very good guides, why am i writing here so?

Easy i was playing with a little app i'm developing but i've just found a little problem... let's explain me it...

I created a sdcard and inside it I placed some jpg files.

So my data path is something like:

/sdcard/app/img/1.jpg
/sdcard/app/img/2.jpg
/sdcard/app/img/3.jpg
/sdcard/app/img/4.jpg
[...]
/sdcard/app/img/n.jpg

Now I want to create a gallery app to show out these files, I looked at demo srcs by android sdk, but they always use imgs from resources...

I decided to try using Bitmapfactory.decodeFile and also Bitmapfactory.decodestream but both seems not to work fine returning a NullPointerException

Here you are a little snippet of my app:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. for(int i=0;i<imgsTokens.length;i++)
  3.  
  4.                         {      
  5.  
  6.                                 Log.d(""+i,"/sdcard/app/img/"+imgsTokens[i]+".jpg");
  7.  
  8.                                 try
  9.  
  10.                                 {
  11.  
  12.                                         FileInputStream is = new FileInputStream(new File("/sdcard/app/img/"+imgsTokens[i]+".jpg"));
  13.  
  14.                             BufferedInputStream bis = new BufferedInputStream(is);
  15.  
  16.                             photos[i] = BitmapFactory.decodeStream(is);
  17.  
  18.                             bis.close();
  19.  
  20.                             is.close();
  21.  
  22.                                        
  23.  
  24.                                         //photos[i] = BitmapFactory.decodeFile("/sdcard/app/img/"+imgsTokens[i]+".jpg");
  25.  
  26.                                 }
  27.  
  28.                                 catch(Exception e)
  29.  
  30.                                 {
  31.  
  32.                                         e.printStackTrace();
  33.  
  34.                                 }
  35.  
  36.                         }
  37.  
  38.  
  39.  
  40.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



any idea how to fix?
gh3
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Sep 22, 2008 1:03 pm
Location: Milan

Top

Postby plusminus » Tue Oct 07, 2008 2:48 pm

Hi gh3,

is the [font=Courier New]FileInputStream is[/font] already null, when going into the decode/functions :?:

Regards,
plusminus :)
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 8 guests