简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM