Android Load Camera image as Bitmap?

You will need to provide more info about your problem, such as a snippet of code that you are using. If you want to know when/why the BitmapFactory. DecodeFile method would return null, you can read directly its source code: casidiablo.in/BitmapFactory.

You will need to provide more info about your problem, such as a snippet of code that you are using. If you want to know when/why the BitmapFactory. DecodeFile method would return null, you can read directly its source code: casidiablo.in/BitmapFactory For example, one of the reasons that causes BitmapFactory.

DecodeFile to return null is if there's a problem while openning the file. Curiously, the developers dont't log anything with such a problem... look at the comment "do nothing. If the exception happened on open, bm will be null.

" public static Bitmap decodeFile(String pathName, Options opts) { Bitmap bm = null; InputStream stream = null; try { stream = new FileInputStream(pathName); bm = decodeStream(stream, null, opts); } catch (Exception e) { /* do nothing. If the exception happened on open, bm will be null. */ } finally { if (stream!

= null) { try { stream.close(); } catch (IOException e) { // do nothing here } } } return bm; } As you can see, the BitmapFactory. DecodeFile does not work standalone... but it uses some other methods of the BitmapFactory class (for instance, BitmapFactory. DecodeStream, BitmapFactory.

NativeDecodeStream, BitmapFactory. FinishDecode, etc. ). The problem could be on one of those methods, so if I were you, I would try to read and understand how they work so that I could know in which cases they return null.

I just posted the code (probably while you were typing up the reply). I'll look into some of those methods like you suggested. Thanks!

– GuyNoir Jun 6 '10 at 16:09 Well alright, I simply tried out the FileInputStream method instead and it actually does say that the file does not exist. Which is very strange considering there is a file there. I'll keep fiddling.

– GuyNoir Jun 6 '10 at 16:15 1 Alright, it seems that the name of the file is the problem. I can actually load the images when I rename them to "image. Jpg" rather than the name based on the timestamp of the photo.

Thanks for the help. Of course I get an OOM exception now, but that's something else to handle. Do you happen to know where I could find the source for the Gallery application (or any for that matter).

I just need to figure out how they can get around the small heap size issue when loading and displaying large images. – GuyNoir Jun 6 '10 at 16:27.

I'm not getting an out of memory error, and superSampling didn't seem to help when I tried it. – GuyNoir Jun 6 '10 at 16:10.

It may sound obvious, but check that your filePath actually points to a file. You mention that you are using a file manager to select the image to open - it's possible that the file manager is returning a path to a content provider instead of a file. There is a more robust way to open files using the ContentResolver class, which can open an InputStream to a content provider, file, or resource, without you needing to know in advance what kind of path you are passing it.

The only catch is that you need to pass a Uri object on the call to openInputStream() instead of a String. Public static Bitmap loadBitmap(String filePath, Context c) { InputStream inStream; try { inStream = c. GetContentResolver().

OpenInputStream( Uri. Parse(filePath) ); } catch (FileNotFoundException e) { // handle file not found } return BitmapFactory. DecodeStream(inStream); } This also happens to be how the ImageView widget attempts to load images when you use its setImageURI method.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions