【问题标题】:Copy and Save an image selected by the user in windows store apps using c#使用 c# 在 Windows 商店应用程序中复制并保存用户选择的图像
【发布时间】:2013-06-01 11:59:41
【问题描述】:

我需要复制用户打开并选择并保存的图像,并在应用重新加载时向用户显示保存的图像。帮我在 Windows 商店应用程序(不是网络应用程序)中显示保存图像。

提前致谢

【问题讨论】:

    标签: c# image save windows-store-apps


    【解决方案1】:

    您应该使用ApplicationDataContainer。将打开的文件保存到应用程序设置,并在加载应用程序时获取并显示。示例this

    【讨论】:

      【解决方案2】:

      用户如何打开并选择图像?使用FileOpenPicker?在这种情况下,只需将其返回的StorageFile 复制到本地存储并始终从那里检索它:

      var picker = new FileOpenPicker();
      picker.FileTypeFilter.Add(".jpg");
      var file = await picker.PickSingleFileAsync();
      
      var copiedFile = await file.CopyAsync(ApplicationData.Current.LocalFolder);
      

      编辑:

      要显示图像,请使用Image 控件。您可以使用 ms-appdata scheme 将源设置为直接在 XAML 中复制的文件:

      <Image x:Name="MyImage" Source="ms-appdata:///local/CopiedFile.jpg" />
      

      或者你可以从代码中设置它的来源:

      MyImage.Source = new BitmapImage(new Uri("ms-appdata:///local/CopiedFile.jpg"));
      

      当然还有其他方法,例如从视图模型绑定Source 属性),具体取决于您要实现的目标。

      【讨论】:

      • 文件正在被存储,但未显示。如何显示存储的文件
      • @lakshmivisalij 我添加了几个示例,如何在我的答案中显示图像。
      • 是的,但这对我不起作用,下面是我的代码
      • public async void Open_Click(object sender, RoutedEventArgs e) { try { rootPage.NotifyUser("正在打开图像文件...", NotifyType.StatusMessage); StorageFile 文件 = 等待 Helpers.GetFileFromOpenPickerAsync(); var 复制文件 = 等待文件.CopyAsync(ApplicationData.Current.LocalFolder); Image1.Source = new BitmapImage(new Uri("ms-appdata:///LocalFolder/file.jpg"));
      • m_fileToken = m_futureAccess.Add(file); m_imageProperties = 等待文件.Properties.GetImagePropertiesAsync(); m_imageProperties = 等待复制文件.Properties.GetImagePropertiesAsync(); string[] requests = { "System.Photo.ExposureTime", // 以秒为单位 "System.Photo.FNumber" // EXIF 规范定义的 F-stop 值 };
      猜你喜欢
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2012-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多