c# - 如何从从图库中挑选的图像中获取文件名?
问题描述
我正在尝试从库中获取文件名,但我正在使用的库似乎没有检索文件名的方法,但它具有检索文件路径的方法,我使用的是 Xam.Plugin.Media。我需要将文件名作为参数传递给我正在使用的其他方法。这是我的代码:
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);
解决方案
用这个。
var fileNameWithExtenstion = Path.GetFileName(filePath);
var fileNameWithoutExtenstion = Path.GetFileNameWithoutExtension(filePath);
推荐阅读
- javascript - JavaScript/jQuery 在脚本中添加锚标记
- javascript - onBlur 事件在加载应用程序 ReactJS 时自动运行
- sql - 设置声明变量的结果排序顺序
- java - JPA 未获取数据引发 stackoverflow 错误
- java - 从 .txt 文件中读取字符串并将内容放入二维数组
- machine-learning - Caffe 错误 - 数据转换器检查失败:datum_channels > 0(0 对 0)
- c++ - C ++如何从函数传递两个结构?
- linq - 使用 HtmlAgilityPack (Linq) 解析 html 表
- sql - PostgreSQL - 检查值是否等于枚举值
- python - 指定替代日期时间格式“例外:无效的日期时间。它必须大于最后一个”