1、path 转 Uri
1)、
public static Uri getImageStreamFromExternal(String imageName) {
File externalPubPath = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES
);
File picPath = new File(externalPubPath, imageName);
Uri uri = null;
if(picPath.exists()) {
uri = Uri.fromFile(picPath);
}
return uri;
}
2)、
public static Uri getMediaUriFromPath(Context context, String path) {
Uri mediaUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = context.getContentResolver().query(mediaUri,
null,
MediaStore.Images.Media.DISPLAY_NAME + "= ?",
new String[] {path.substring(path.lastIndexOf("/") + 1)},
null);
Uri uri = null;
if(cursor.moveToFirst()) {
uri = ContentUris.withAppendedId(mediaUri,
cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
}
cursor.close();
return uri;
}
1、通过Uri 直接获取Bitmap
Bitmap bitmap = MediaStore.Images.Media.getBitmap( contentResolver, uri);
网友评论