android - Uno Platform Android 和 UWP:如何将文件复制到本地文件夹?
问题描述
我正在尝试选择图片文件并将它们复制到应用程序本地文件夹,并将路径保存为数据库中的字符串以显示图像,该代码在 UWP 上运行良好,但在 Android 上运行不正常(我使用的是 Uno 平台):
string SImag = string.Empty;
private async Task<string> MediaxPicAsync()
{
Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".bmp");
openPicker.FileTypeFilter.Add(".gif");
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
try
{
Windows.Storage.StorageFile temp = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("TempFile." + file.FileType);
await file.CopyAndReplaceAsync(temp);
return temp.Path;
}
catch (Exception ex)
{
await new Windows.UI.Popups.MessageDialog("Could not open image!", "Error image loading").ShowAsync();;
}
}
return string.Empty;
}
Xaml 代码:
<Image>
<Image.Source>
<BitmapImage UriSource="{x:Bind SImag, Mode=OneWay,Converter={StaticResource appClsConvStr2Imag}}" />
</Image.Source>
</Image>
转换器:
public class ClsConvStr2Imag : Windows.UI.Xaml.Data.IValueConverter
{
object Windows.UI.Xaml.Data.IValueConverter.Convert(object value, Type targetType, object parameter, string language)
{
if (string.IsNullOrEmpty(value as string))
{
return null;
}
else
{
string sPath = (string)value;
if (sPath.Contains("/") | sPath.Contains("\\"))
{
}
else
{
if (parameter == null)
{
sPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\" + sPath;
}
else
{
sPath = Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\" + parameter + "\\" + sPath;
}
}
return new Uri(sPath);
}
}
object Windows.UI.Xaml.Data.IValueConverter.ConvertBack(object value, Type targetType, object parameter, string language)
{
return value;
}
}
在 Android 调试期间的 Visual Studio 输出中,它显示错误为:
[BitmapFactory] Unable to decode stream: java.io.FileNotFoundException: /data/user/0/Sale.Sale/files/TempFile.png (No such file or directory)
任何克服这个问题的帮助都是非常受欢迎的,我做了 3 天的研究,找不到这个问题的干净解决方案。非常感谢您的时间和专业知识。
解决方案
推荐阅读
- notepad++ - Notepad++ 中的比较和书签 + 行
- django - Django 部署到 AWS EB 显示 500 内部服务器错误
- c# - 如何让IIS不拒绝SignIn?ReturnUrl=%2F?
- python - 如何在 django rest 框架中创建加密密码
- vivado-hls - a.at
(x,y) 在 Vivado SDSoC 中不起作用 - java - GWT:ClosingEvent setMessage 有效,但未显示消息
- python - 将网络摄像头流式传输到 aws ec2instance
- c# - 使用 Team Foundation Server 创建 NuGet 缺少依赖项
- javascript - dayJS 中 moment.locales() 的替代方法是什么
- sql - 本月每周至少观看一部电影的所有用户列表