Oleksandr Firsov Oleksandr Firsov - 1 year ago 72
Android Question

Bitmap height not showing up in LogCat

So, I'm working on an app, and I need to get image height. This image is stored on the phone. To do this I use following code:

photoPath = "file://" + Environment.getExternalStorageDirectory() + "/WIP/test.jpg";
Log.i("Debuguo", photoPath);
Bitmap bitmapWV = BitmapFactory.decodeFile(photoPath);
Log.i("Debuguo", "Test");
String info = Float.toString(bitmapWV.getHeight());
Log.i("Debuguo", info);

But the problem is that the height of the bitmap doesn't show up in LogCat. I've set up 2 more debug points to check whether the rest works, I get the
string and
in the debug window, but no height. I thought something could be wrong with the bitmap itself, so I tried different approach of creating it, but still no changes:

public static Bitmap getBitmapFromUrl(String src) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(src, options);
return bitmap;

Honestly, this is the first time I've encountered such issue - no errors, debug not showing a thing. I have no idea what have caused it.

Answer Source

Remove "file://" prefix

String photoPath = Environment.getExternalStorageDirectory() + "/WIP/test.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(photoPath);