简体   繁体   English

如何从从图库中挑选的图像中获取文件名?

[英]How can I get the file name from an image picked from the gallery?

I am trying to get the filename from the gallery but the library I am using doesn't seem to have the method to retrieve the file name but it has the method for retrieving the file path, I am using the Xam.Plugin.Media.我正在尝试从图库中获取文件名,但我正在使用的库似乎没有检索文件名的方法,但它具有检索文件路径的方法,我使用的是 Xam.Plugin.Media。 I need the filename to pass it as an argument in the other method I am using.我需要将文件名作为参数传递给我正在使用的其他方法。 Here is my code:这是我的代码:

   var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new 
   Plugin.Media.Abstractions.PickMediaOptions
            {
                PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
           
            });


            if (file == null) return;
            imgChoosed.Source = ImageSource.FromStream(() => {
                var stream = file.GetStream();
                return stream;
            });

            // computerVision = new ComputerVisionViewModel();

           //I need to pass the file name as an argument here
           // var result = await computerVision.ConnectToVisualRecognition(file.Path,file.Name);

use this.用这个。

var fileNameWithExtenstion = Path.GetFileName(filePath);
var fileNameWithoutExtenstion = Path.GetFileNameWithoutExtension(filePath);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM