2017-06-14 57 views
0

我使用VS 2017,我需要从其他应用程序接收图像。所以它基本上是App-App通信。我是UWP和Windows Mobile开发人员的新成员,所以我研究了很多,并且设法使用共享内容获取DataPackage。Reciving Image-UWP

当您尝试来研究这个:

if (this.shareOperation.Data.Contains(StandardDataFormats.Bitmap)) 
{ 
    this.sharedBitmapStreamRef = await this.shareOperation.Data.GetBitmapAsync(); 

    //catch (Exception ex) 
    //{ 
    // NotifyUserBackgroundThread("Failed GetBitmapAsync - " + ex.Message, NotifyType.ErrorMessage); 
    //} 
} 

问题是,应用程序不会看到我的文件作为位图。 当我尝试获取recived文件的类型时,它给了我System .__ COMObject。 我管理获取文件作为storageitem,但我无法读取IRandomAccessStreamReference。 As StorageItem I get,path,name etc.

ShareTarget示例应用程序发生同样的事情,它也不会将图像视为BitMap(formatId)。 有什么建议吗?

+0

那么,为什么不加载StorageItem到BitmapImage的? –

+0

ShareSource是否使用'DataPackage.SetBitmap'方法设置DataPackage中包含的位图图像?如果是这样,ShareOperation.Data.Contains(StandardDataFormats.Bitmap)将返回'true'。你也可以检查什么是StandardDataFormats类型。 –

+0

@IgorKulman我从图库或文件资源管理器共享数据。我通过从IStorageItem中读取路径来加载BitmapImage,然后创建一个StorageFIle。我的下一个问题是,它只有在文件位于图片(内部存储)文件夹中才有效。我也增加了打开pdf的可能性。并在.pdf文件位于图片文件夹中时打开。我现在正在寻找我需要什么权限以及如何实现文件类型关联。有什么建议么? –

回答

0

请参考msdn上的示例https://code.msdn.microsoft.com/How-to-share-data-between-6ef0a355

目标应用:

if (operation.Data.Contains(StandardDataFormats.Bitmap)) 
{ 
    shareType.Text = "Bitmap"; 
    shareTitle.Text = operation.Data.Properties.Title; 
    imgShareImage.Visibility = Visibility.Visible; 
    tbShareData.Visibility = Visibility.Collapsed; 
    RandomAccessStreamReference imageStreamRef = await operation.Data.GetBitmapAsync(); 
    IRandomAccessStreamWithContentType streamWithContentType = await imageStreamRef.OpenReadAsync(); 
    BitmapImage bitmapImage = new BitmapImage(); 
    bitmapImage.SetSource(streamWithContentType); 
    imgShareImage.Source = bitmapImage; 
} 
+0

我现在构建该项目,它不识别位图,只是打破所有shareoperations语句,没有输出,其重要我需要这个工作在Windows Phone –

+0

我试过在我的设备上,它工作正常。 –

+0

我将.pdf或图像对象作为system_combobject接收,并且仅将其识别为存储项目。我使用从路径创建存储文件。 –

相关问题