Reputation: 1
I have created app in wp8.1 rt. When button is clicked i need to take screen shot of page and share it on social media(like facebook,twiter ,...). Upto now what i have done is -
DataTransferManager dtManager = DataTransferManager.GetForCurrentView();
dtManager.DataRequested += dtManager_DataRequested;
private async void dtManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
e.Request.Data.Properties.Title = "here is title";
e.Request.Data.Properties.Description = "H..........";
e.Request.Data.SetWebLink(new Uri("http://......."));
//here i need to add image also
}
private void share_Click(object sender, RoutedEventArgs e)
{
Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
}
Upto here its working ,i am able to share title, discription,.... but unable to share image that capture programatically For capturing image what i have done is below:
private async Task<RenderTargetBitmap> CreateBitmapFromElement(FrameworkElement uielement)
{
try
{
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(uielement);
return renderTargetBitmap;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
return null;
}
img.source= await CreateBitmapFromElement(rootcontent); //here rootcontent is my grid name that i need to capture.
Here i am able to get imge also. But unable to share this captured image. I read some blogs but still unable to solve it. I think i need to convert it to BitmapImage. How can i do that?? Or is there another best way of handling this problem.
what I need is when share button is clicked ,i need to capture screenshot and share it on social media (like facebook).
Upvotes: 0
Views: 288
Reputation: 4680
You can use e.Request.Data.SetBitmap to transfer a screen shot. But the parameter type of this method is RandomAccessStreamReference, so you need to convert the RenderTargetBitmap to RandomAccessStreamReference.
The essential idea is: Get the pixels and write the pixels to a InMemoryRandomAccessStream.
You can find the code reference from article How to use the RenderTargetBitmap in Windows 8.1.
Upvotes: 1