四年前,我开始开发一个应用程序,允许用户选择图像,然后应用程序动画图像。我在Eclipse中完成了工作,我100%确定应用程序正常工作。
快进到2018年,我仍然有旧的源代码,我想改进它。我将它导入Android Studio,它仍然可以构建和运行。
然而,自那时起Android的工作方式必定会有所改变,因为现在这些图像变空了。
在调试中,我发现计算selectedImagePath
,它不是空的,因此我认为它是正确的。
在模拟器中运行时的一个示例:/document/primary:Download/x.gif
(当然存在该图像)。
在手机上运行时的一个示例:/document/image:2375
(令人困惑的是,它实际上称为x.png
并位于标准的下载文件夹中。)
仍然,bitmap
始终为空。有什么想法吗?
Uri selectedImageUri;
selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath);
public String getPath(Uri uri) {
String selectedImagePath;
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if(cursor != null){
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
selectedImagePath = cursor.getString(column_index);
}else{
selectedImagePath = null;
}
if(selectedImagePath == null){
//2:OI FILE Manager --- call method: uri.getPath()
selectedImagePath = uri.getPath();
}
return selectedImagePath;
}
答案 0 :(得分:1)
df2=pd.DataFrame(data=[[1,np.nan,np.nan],[2,np.nan,np.nan],[3,2,3],[4,4,5],[5,6,7],
[1,np.nan,np.nan],[2,np.nan,np.nan],[3,np.nan,np.nan],[4,np.nan,np.nan],[5,2,3],
[1,np.nan,np.nan],[2,np.nan,np.nan],[3,np.nan,np.nan],[4,4,5],[5,6,7]],
columns=['day','d','c'],index=[32,32,32,32,32,44,44,44,44,44,55,55,55,55,55])
print(df2)
day d c
32 1 NaN NaN
32 2 NaN NaN
32 3 2.0 3.0
32 4 4.0 5.0
32 5 6.0 7.0
44 1 NaN NaN
44 2 NaN NaN
44 3 NaN NaN
44 4 NaN NaN
44 5 2.0 3.0
55 1 NaN NaN
55 2 NaN NaN
55 3 NaN NaN
55 4 4.0 5.0
55 5 6.0 7.0
更改为
Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath);
答案 1 :(得分:0)
尝试检查您的uri是否从file://
开始private String getImagePathFromUri(Uri imageUri) {
if (imageUri != null) {
if (imageUri.toString().startsWith("file://")) {
return imageUri.getEncodedPath();
} else {
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(imageUri,
filePathColumn, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String imageEncoded = null;
try {
imageEncoded = cursor.getString(columnIndex);
} catch (IllegalStateException e) {
e.printStackTrace();
}
return imageEncoded;
}
cursor.close();
}
}
}
return null;
}