自动复制多个图像并显示图块通知?

时间:2012-05-22 09:37:59

标签: c# windows-8

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

public sealed partial class 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());
            }
        }

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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的功能。