Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 388
NullPointerException Avatar asked Mar 02 '12 10:03

NullPointerException


People also ask

Can a JPEG be converted to a bitmap?

A color JPG image can be converted to a color bitmap by saving it in the steps below as a color bitmap. Open Microsoft Paint by selecting Start > Programs > Accessories > Paint. Click File > Open. Find and select your logo then click Open.

How to open bitmap in android?

Viewing BMP Files on AndroidThe Gallery app is the default file viewer for images on the stock version of Android, so this app opens whenever you tap on a BMP file (whether it's stored on an SD card or attached to an email).


2 Answers

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.

like image 123
Bigflow Avatar answered Oct 11 '22 19:10

Bigflow


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.

like image 23
Jave Avatar answered Oct 11 '22 20:10

Jave