无法在Windows 10中使用DataTransferManager共享图像 [英] Unable to share image using DataTransferManager in Windows 10
问题描述
要求:使用 DataTransferManager
在Windows 10中的Facebook共享文本和图像。
Requirement: Share a text and image using DataTransferManager
into Facebook in Windows 10.
问题:无法分享图片。
下面显示的是我使用的代码,
Below shown is the code I used,
private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequestDeferral deferral = args.Request.GetDeferral();
args.Request.Data.Properties.Title = "Sharing sample";
args.Request.Data.SetText("Testing share in universal app");
var imageUri = "http://cdn.vrworld.com/wp-content/uploads/2015/01/microsoft-announces-windows-10_ahab.1920.jpg";
//var storageFile = await StorageFile.CreateStreamedFileFromUriAsync("ShareFile", new Uri(imageUri), null);
//List<IStorageItem> storageItems = new List<IStorageItem>();
//storageItems.Add(storageFile);
//args.Request.Data.SetStorageItems(storageItems);
args.Request.Data.SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(imageUri)));
deferral.Complete();
}
当我使用 SetBitmap
方法,只有标题和文本被共享。图像既不显示在共享面板中也不会共享到目标应用程序。
When I use SetBitmap
method, only the title and text are being shared. The image is neither displayed in the share panel nor shared to the target app.
当我使用 SetStorageItems
(见评论的代码),没有任何项目被共享。默认的你在想什么文本显示在共享面板上。
When I use SetStorageItems
(see commented code), none of the items are shared. The default "What's on your mind" text appears on the share panel.
任何反馈都表示赞赏,谢谢!
Any feedback is appreciated, thank you!
推荐答案
不幸的是不支持共享URI流文件。以下是我如何做:
Sharing of URI streamed files is unfortunately not supported. Here's how I would go about doing this:
- 当用户单击共享按钮时,开始下载文件
并显示一些如果它是一个大文件,进度如何。当然也可以
预先下载文件。设置包含该文件的StorageFile
实例
。 - 调用 DataTransferManager.ShowShareUI
- 在您的
DataRequested
处理程序,使用SetStorageItems
共享StorageFile
实例。
- When the user clicks the share button, start downloading the file
and show some sort of progress if it's a big file. You could also
pre-download the file of course. Set up a
StorageFile
instance containing the file. - Call DataTransferManager.ShowShareUI
- In your
DataRequested
handler, useSetStorageItems
to share theStorageFile
instance.
这篇关于无法在Windows 10中使用DataTransferManager共享图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!