BitmapFactory returns null on HTC Incredible & Desire

All your problems with Audio, Video and Images.

BitmapFactory returns null on HTC Incredible & Desire

Postby tmschmal » Thu May 13, 2010 3:03 am

Hi,

I'm trying to decode a JPG into a Bitmap using BitmapFactory.decodeFile("/sdcard\image.jpg"), however on the Incredible and Desire it keeps returning null. Yes, the sdcard is installed, so I don't think it's related to that at all. The BitmapFactory just returns null, but doesn't give any kind of useful error as to why it was unable to decode the jpg file into a Bitmap. This code has been working just fine on all other Android devices.

Does anyone know of any reason why it would be different on the Incredible/Desire, or how I can troubleshoot this to figure out what the issue is?

Thanks.
tmschmal
Freshman
Freshman
 
Posts: 4
Joined: Sun May 02, 2010 8:48 pm

Top

Re: BitmapFactory returns null on HTC Incredible & Desire

Postby mrco » Tue May 18, 2010 12:32 pm

Did you check logs messages?
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

Re: BitmapFactory returns null on HTC Incredible & Desire

Postby tmschmal » Tue May 18, 2010 12:54 pm

I did. Nothing was displayed because returning null is an 'expected' behavior of decodeFile(). I did come up with a couple work arounds in case any else encounters this issue.

BitmapFactory.decodeStream(FileInputStream);

The other, less preferred option is to copy the image file to the data directory for the app and then use decodeFile().

I don't have an explanation as to why this is the behavior, but this is what I experienced.
tmschmal
Freshman
Freshman
 
Posts: 4
Joined: Sun May 02, 2010 8:48 pm

Re: BitmapFactory returns null on HTC Incredible & Desire

Postby mrco » Tue May 18, 2010 1:09 pm

tmschmal wrote:Hi,
BitmapFactory.decodeFile("/sdcard\image.jpg")

Ok, may be problem with "\"? In unix systems file path separator is "/" char.

Or this is only mistype in your post....
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

Re: BitmapFactory returns null on HTC Incredible & Desire

Postby tmschmal » Tue May 18, 2010 1:57 pm

That's just a typo, I simplified the full string of path variables for the post. It worked fine all all Android devices except Incredible & Desire. I was able to access the image file using the File class and getReadable() returned true, so that confirms that the path/rights are correct.
tmschmal
Freshman
Freshman
 
Posts: 4
Joined: Sun May 02, 2010 8:48 pm

Re: BitmapFactory returns null on HTC Incredible & Desire

Postby Shota » Sun Jun 13, 2010 5:02 pm

Hi! I have a similar problem on HTC Hero.

Only one image can be decoded correctly. But second image - not!

Code: Select all
File f = new File("/sdcard/DCIM/100MEDIA/");
File files[] = f.listFiles();
if(files.lenght > 1)
{
Bitmap b1 = null, b2 = null;
b1 = BitmapFactory.decodeFile(files[0].getPath());
/* IT'S OK! */
b2 = BitmapFactory.decodeFile(files[1].getPath());
/* ERROR! */
}

But it's works correct on the emulator.
I can't understand why so occurs! Somebody knows?
Shota
Freshman
Freshman
 
Posts: 5
Joined: Tue May 18, 2010 6:57 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: DaveWest, Yahoo [Bot] and 26 guests