3

这是我的 Windows 8 Metro 应用程序代码,其中我将 1 个图像从本地文件夹复制到我的应用程序存储文件夹,然后它显示一个磁贴通知。请帮我自动复制图片库中的所有图像,然后这些图像显示在平铺通知中。我不知道如何访问或复制图片库中的所有图像...没有用于复制图像的用户界面。

公共密封部分类 BlankPage : Page { string imageRelativePath = String.Empty;

    public BlankPage()
    {
        this.InitializeComponent();
        CopyImages();
    }

    public async void CopyImages()
    {

        FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
        picker.ViewMode = PickerViewMode.Thumbnail;
        picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        picker.FileTypeFilter.Add(".jpg");
        picker.FileTypeFilter.Add(".jpeg");
        picker.FileTypeFilter.Add(".png");
        picker.CommitButtonText = "Copy";
        StorageFile file = await picker.PickSingleFileAsync();
        StorageFile newFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(file.Name);
        await file.CopyAndReplaceAsync(newFile);
        this.imageRelativePath = newFile.Path.Substring(newFile.Path.LastIndexOf("\\") + 1);

                IWideTileNotificationContent tileContent = null;
                ITileWideImage wideContent = TileContentFactory.CreateTileWideImage();
                wideContent.RequireSquareContent = false;
                wideContent.Image.Src = "ms-appdata:///local/" + this.imageRelativePath;
                wideContent.Image.Alt = "App data";
                tileContent = wideContent;
                tileContent.RequireSquareContent = false;
                TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());
            }
        }
4

2 回答 2

2

首先给出图像文件夹的路径,然后通过 IReadOnlyList 列出这些图像,并将复制图像上的循环设置为结束,然后在 TileUpdateManager 上设置计时器。它会起作用。

于 2012-05-23T06:03:49.817 回答
0

枚举 PicturesLibrary 中的文件:

// from my sample app "MetroContractSample" http://metrocontractsample.codeplex.com/documentation
var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".jpg", ".png", ".bmp", ".gif", }) { FolderDepth = FolderDepth.Deep, };
StorageFileQueryResult query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
var fileInfoFactory = new FileInformationFactory(query, ThumbnailMode.SingleItem);
IReadOnlyList<FileInformation> fileInfoList = await fileInfoFactory.GetFilesAsync();

注意:您必须在 Package.appxmanifest 中声明 PicturesLibrary 的功能。

于 2012-05-22T13:27:04.070 回答