如何在没有 FilePicker 的情况下在固定位置保存和加载 InkCanvas gif 文件 [英] How to save and load InkCanvas gif file at fixed location without FilePicker

查看:28
本文介绍了如何在没有 FilePicker 的情况下在固定位置保存和加载 InkCanvas gif 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有 FilePicker 的情况下保存和加载 InkCanvas gif 文件.

I want to save and load InkCanvas gif file without FilePicker.

我看到了一个示例 使用 FilePicker,但我想在单击保存按钮时自动保存 gif 文件.

I saw a sample using FilePicker, but I want to save the gif file automatically when I click the save button.

例如,当我保存 1 个 InkCanvas gif 文件时,

For example, when I save 1 InkCanvas gif file,

然后将 gif 文件保存在我的 C: 驱动器上的特定文件夹中.

Then the gif file is saved at in a specific folder on my C: drive.

我还希望文件名自动增长,以便我可以加载特定的 InkCanvas 文件.

I also want the file name grow automatically, so that I can load specific InkCanvas file.

这可能吗?

推荐答案

UWP 应用在沙箱中运行,以便用户可以知道应用在做什么以及它访问了她硬盘驱动器上的哪些文件.

UWP apps run in a sandbox, so that the user can know what the app is doing and which files on her hard drive it accesses.

如果您想将文件保存到用户硬盘驱动器上的某个位置,您必须首先获得对该位置的访问权限.有几种方法可以实现这一点:

In case you want to save files to a location on the user's hard drive, you will have to be given access to this location first. There are several options how to achieve this:

  1. FileSavePicker - 您发现的选项,但它需要用户每次手动选择目标文件.如果您想在下次打开应用程序时访问所选文件,您可以利用FutureAccessList,您可以将StorageFile 存储在一个键下,这将允许您下次再找回来.
  2. FolderPicker - 让用户使用对话框选择应存储图像的文件夹,您将获得对该文件夹的读/写权限.然后,您可以根据需要轻松地在那里创建新文件.如果您想在下次打开应用程序时访问此选定位置,您可以利用FutureAccessList,您可以将StorageFolder 存储在一个键下,这将允许您下次再找回来.
  3. 图片库 - 您的应用程序可以在 package.appxmanifest 文件中声明 picturesLibrary 功能,然后访问用户的图片库以进行如下编写:Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);
  4. 广泛的文件系统访问 - 这是终极"解决方案,需要您的应用定位Windows 10 的 Spring Creators Update(2018 年 4 月待发布)或更高版本.您必须在应用的清单中声明 broadFileSystemAccess 功能,然后您就可以直接访问用户有权访问的任何文件系统路径.唯一的问题是您需要有充分的理由来执行此操作(例如构建文件资源管理器应用程序或类似的),因为在 Microsoft Store 认证期间会检查此功能,如果出现以下情况,您的应用程序可能会被拒绝对于您要发布的应用程序类型,此功能的存在似乎是不必要的.
  1. FileSavePicker - the option you have discovered, but it requires the user to select the destination file each time manually. If you want to access the selected file next time the app is opened, you can utilize FutureAccessList, where you can store the StorageFile under a key, which will allow you to retrieve it again next time.
  2. FolderPicker - let the user select the folder where the images should be stored using a dialog, and you will get read/write permission to this folder. You can then easily create new files there as you require. If you want to access this selected location next time the app is opened, you can utilize FutureAccessList, where you can store the StorageFolder under a key, which will allow you to retrieve it again next time.
  3. Pictures library - your app can declare the picturesLibrary capability in the package.appxmanifest file and then get access to the user's pictures library for writing like this: Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);
  4. Broad file system access - this is the "ultimate" solution and requires your app to target the Spring Creators Update of Windows 10 (pending release in April 2018) or later. You must declare the broadFileSystemAccess capability in your app's manifest and then you can directly access any filesystem path the user has access to. The only problem with this is that you need to have a good reason to do this (like building a file explorer app, or similar), because this capability is checked during Microsoft Store Certification and it is possible that your app would get rejected if the presence of this capability would seem unnecessary for the type of application you are publishing.

这篇关于如何在没有 FilePicker 的情况下在固定位置保存和加载 InkCanvas gif 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆