asitis
asitis

Reputation: 3031

How do we share multiple images or a combination of image with text at a time via Windows 8 Share Charm in c#

I have a list of Image Urls & wants to Share those Images [from each url] at a time through Windows 8 share charm .

Here is the code i used for sharing one WriteableBitmap Image at a time.

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)));           
        }
}


How we can share a multiple images at a time via Share Charm .
Can we share a combination of image and text ?
Please give me an idea if it is possible.

Upvotes: 2

Views: 440

Answers (1)

Farhan Ghumra
Farhan Ghumra

Reputation: 15296

UPDATE 1

Below code shows how to share multiple image URLs via share charm.

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);
}

If all are Internet URLs then you can share it by creating an HTML document from those URLs. If you have multiple StorageFile then you can share with DataPackage.SetStorageItems. It accepts IEnumerable<IStorageItem>.

DataPackage.SetBitmap accepts only one bitmap at a time because normally the destination apps which accepts image majorly deals with single image. If app requires multiple image then I would recommend to use DataPackage.SetStorageItems

Upvotes: 3

Related Questions