How can I read an image file into bitmap from sdcard?
_path = Environment.getExternalStorageDirectory().getAbsolutePath(); System.out.println("pathhhhhhhhhhhhhhhhhhhh1111111112222222 " + _path); _path= _path + "/" + "flower2.jpg"; System.out.println("pathhhhhhhhhhhhhhhhhhhh111111111 " + _path); Bitmap bitmap = BitmapFactory.decodeFile(_path, options );
I am getting a NullPointerException for bitmap. It means that the bitmap is null. But I have an image ".jpg" file stored in sdcard as "flower2.jpg". What's the problem?
If you have a string base64 and need to convert it to a bitmap, this is the simplest and natural method. Code: String base64String = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAA..."; String base64Image = base64String.
The MediaStore API is probably throwing away the alpha channel (i.e. decoding to RGB565). If you have a file path, just use BitmapFactory directly, but tell it to use a format that preserves alpha:
BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options); selected_photo.setImageBitmap(bitmap);
or
http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html
It works:
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With