所以,我正在使用一个应用程序,我需要获取图像高度。此图像存储在电话上。为此,我使用以下代码:
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);
但问题在于,位图的高度未显示在logcat中。我已经设置了另外2个调试点,以检查其余的是否有效,我在调试窗口中获得photoPath
字符串和"Test"
,但没有高度。我认为位图本身可能有问题,因此我尝试了不同的方法来创建它,但仍然没有更改:
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;
}
老实说,这是我第一次遇到这样的问题 - 没有错误,调试没有显示任何事情。我不知道是什么原因造成的。
删除" file://"前缀
String photoPath = Environment.getExternalStorageDirectory() + "/WIP/test.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(photoPath);