MediaStore.Images.Media.insertImage 得到保存图片的原始路径

来源:互联网 发布:战舰世界岛风鱼雷数据 编辑:程序博客网 时间:2024/05/22 15:13

String bitPath = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, “”, "");

Uri uuUri= Uri.parse(bitPath);
String path =  getRealPathFromURI(uuUri);


public String getRealPathFromURI(Uri contentUri) {//通过本地路经 content://得到URI路径
Cursor cursor = null;
        String locationPath = null ;
        try {
        String[] proj = { MediaStore.Images.Media.DATA };
        cursor= getContentResolver().query(contentUri, proj, null, null, null);
             int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
             cursor.moveToFirst();
             locationPath = cursor.getString(column_index);
} catch (Exception e) {
}finally{
if(cursor != null)
{
cursor.close();
}
}
        return locationPath;
    }

0 0
原创粉丝点击