如何获取所选图像的路径

时间:2015-11-17 10:31:32

标签: android image android-imageview android-image

目前我正在拍摄camera and gallery的照片。当我从相机拍照时,路径为storage/sdcard0/pictures/androidfileupload/

 private static File getOutputMediaFile(int type) {

    // External sdcard location
    File mediaStorageDir = new File(
            Environment
                    .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            "Android File Upload");

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {

            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
            Locale.getDefault()).format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");
    }  else {
        return null;
    }

    return mediaFile;
}

所以从上面的代码我得到了storage/sdcard0/pictures/android file upload/

现在我正在从图库中选择图像,因此显示错误storage/sdcard0/pictures/androidfileupload/imagename.jpg未找到。

我已调试代码,我从图库content://media/external/images/media/26435获取所选图像的路径,但我想要路径 content://media/external/images/media/imagename.jpg

那么如何才能获得imagename.jpg的路径。?

0 个答案:

没有答案