BigFI
October 9, 2015, 9:35am
1
Hello,
I’m trying to share a screenshot of my end game through the share charm of the universall app.
So I’m able right now to share text via the datatransfer manager like explained here :
But I’m unable to share an image with that.
I first use the Application.CaptureScreenshot(“screen.png”). After that, I try to reload it in a storagefile, convert it in a RandomAccessStreamReference to use it with the SetBitmap.
But I always have an error. Since I move to Win10+VS2015, I’m unable to see the c# in visual studio so I don’t have the error.
Has somebody done this before and can share his method?
Thank you in advance.
Karim
What do you mean by you can’t see C# in vs2015? Which files can’t you see exactly? Sharing a code snippet of your attempt might also help.
BigFI
October 9, 2015, 12:11pm
3
Yes, sorry for that. I forgot to copy that before coming to work. I will put my code as soon as I come home.
Maybe a I misunderstood. But when you build your universal app and check the C# option, you can open your project in VS and see the C# files?
Of course you can. But you mentioned in the first post that something stopped working with vs2015 so I got confused. Anyway, let’s see your code.
BigFI
October 9, 2015, 3:50pm
5
Here is my code.
First I use the capturescreenshot
Application.CaptureScreenshot("background.png");
And after, the user click a buton to share it
public void ShareButton()
{
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
#if NETFX_CORE
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
#endif
}, false);
}
#if NETFX_CORE
private async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
try{
DataRequest request = e.Request;
request.Data.Properties.Title = "My highscore in Cemetery Rush";
request.Data.Properties.Description = "An example of how to share text.";
request.Data.SetText("Woop woop");
Windows.Storage.StorageFile sampleFile = await ApplicationData.Current.LocalFolder.GetFileAsync("background.png");
request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(sampleFile));
}
catch (Exception ex)
{
Debug.Log(ex.Message);
}
}
#endif
The code share all the text but not the image
Did you check that backround.png is really saved to Local folder? Try provide absolute path for ex., Application .CaptureScreenshot (Path.Combine(Windows.Directory.localFolder, “background.png”));
BigFI
October 10, 2015, 2:41pm
7
Thank you Tomas for the advice.
Windows.Directory is not a Win store name space.
But I tried with
Application.CaptureScreenshot(Path.Combine(ApplicationData.Current.LocalFolder.Path, "background.png"));
to save, and I still use
Windows.Storage.StorageFile sampleFile = await ApplicationData.Current.LocalFolder.GetFileAsync("background.png");
request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(sampleFile));
to open it.
But it’s still not working.
Could you copy paste the error message?
BigFI
October 11, 2015, 2:07pm
9
Tomas,
I don’t have any error.
I just display the path of where the screenshot is saved and what I get for the sampleFile.
The screen is saved at
and it’s open after. The sampleFile path is
Sorry I didn’t do the test before. So the file with this configuration, is open. But not display in Facebook, mail or Twitter.
Ignas83
October 12, 2015, 2:39pm
10
I’ve tried your code sample and it worked fine with Mail. The only thing that went wrong was that Unity failed to capture screenshot but I fixed that. Can you confirm that Background.png file is actually created?
BigFI
October 13, 2015, 6:26am
11
What did you do to fix it?
The file exist because I open it with getfileasync.
Ignas83
October 13, 2015, 7:57am
12
Hm, could you share your project? Because the code that you pasted works fine in my test project. Or you need to find a way to give us exact error
BigFI
October 13, 2015, 8:52am
13
Ok, that’s weird.
I have no error. Every thing go well. It’s just that I don’t have the image after the share.
I’m away on vacation for a week. Will try a dummy project when I come back. Thanks for your help.
BigFI
October 19, 2015, 2:09pm
14
Ok, I did a simple test.
I tested it on Windows 10 (Universal app 8.1) and it worked.
So the bug is only on Windows phone 8.1.
Hy There,
I can share the image by email, but if I tried using Skype, I’ve got only the text … (And the share UI does not show FaceBook …)
Any idea ?