2

我有一个列表Image Urls& 想要Share这些图像 [来自每个 url] 一次通过Windows 8 share charm.

这是我用于WriteableBitmap Image一次共享一个的代码。

var dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += DataRequested;  

public void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
        DataRequest request = args.Request;
        DataRequestDeferral deferral = request.GetDeferral();
        try
        {   
           request.Data.SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(ImageUrl)));           
        }
}


我们如何share a multiple images一次通过Share Charm.
我们可以分享图像和文字的组合吗?
如果可能,请给我一个想法。

4

1 回答 1

3

更新 1

下面的代码显示了如何通过共享魅力共享多个图像 URL。

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += DataRequested; 
}

public void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
    var Images = new List<string> 
    {
        "http://jenswinter.com/image.axd?picture=stackoverflow-logo-250.png",
        "http://en.flossmanuals.net/thunderbird/getting-support/_booki/thunderbird/static/Thunderbird-Support-tbird_support_superuser-en.jpg",
        "http://www.thomas-steinbrenner.net/wp-content/uploads/2010/11/Stackexchange_logo.png"
    };

    var res = GetHtml(Images);
    DataRequest request = args.Request;

    // The title is required. Otherwise it won't be shared.
    request.Data.Properties.Title = "Multi Image via Share Charm Using HTML.";
    DataRequestDeferral deferral = request.GetDeferral();
    try
    {
        string htmlFormat = HtmlFormatHelper.CreateHtmlFormat(res);
        request.Data.SetHtmlFormat(htmlFormat);
    }
    catch { }
    finally { deferral.Complete(); }
}

private string GetHtml(List<string> ImageUrls)
{
    string ImgTag = @"<img src='{0}' /><br />";
    string Html = @"<html>
                <head>
                <title>Multi Image via Share Charm</title>
                </head>
                <body>
                {0}
                </body>
                </html>";
    string AllImgTags = "";
    foreach (var url in ImageUrls)
    {
        AllImgTags += string.Format(ImgTag, url);
    }

    return string.Format(Html, AllImgTags);
}

如果都是 Internet URL,那么您可以通过从这些 URL 创建 HTML 文档来共享它。如果您有多个StorageFile,那么您可以与DataPackage.SetStorageItems. 它接受IEnumerable<IStorageItem>.

DataPackage.SetBitmap一次只接受一个位图,因为通常接受图像的目标应用程序主要处理单个图像。如果应用程序需要多个图像,那么我建议使用DataPackage.SetStorageItems

于 2013-09-19T12:20:36.343 回答