NullPointerException
NullPointerException

Reputation: 37733

How to open a JPG file as a BITMAP with the JPG stored on the SDCARD?

Actually i know how to open PNG files as bitmaps. But my code doens't works for open JPG files, i dont know why.

I can't find correct examples on SO or google about how to do this.

I need to have a bitmap with the JPG file opened from a dir of the sdcard. For example "sdcard/images/01.jpg"

Thanks

Upvotes: 32

Views: 54319

Answers (2)

Bigflow
Bigflow

Reputation: 3666

File root = Environment.getExternalStorageDirectory();
ImageView IV = (ImageView) findViewById(R.id."image view");
Bitmap bMap = BitmapFactory.decodeFile(root+"/images/01.jpg");
IV.setImageBitmap(bMap);

Always try to use Environment.getExternalStorageDirectory(); instead of sdcard. You need an ImageView somewhere in your layout, however that's how I do this kind of things.

I use this code personally too, and it works here.

Upvotes: 55

Jave
Jave

Reputation: 31856

Any of the BitmapFactory.decode* methods should be able to handle standard JPG files.
If you post some code it could be easier to see why it won't work.

Upvotes: 11

Related Questions