C# 接收图像超宽带
我正在使用VS2017,我需要从其他应用程序接收图像。所以它基本上是应用程序通信。我是UWP和windows mobile开发方面的新手,所以我做了很多研究,并设法获得具有共享内容的数据包 当您尝试检查此项时:C# 接收图像超宽带,c#,uwp,windows-phone,windows-10-universal,C#,Uwp,Windows Phone,Windows 10 Universal,我正在使用VS2017,我需要从其他应用程序接收图像。所以它基本上是应用程序通信。我是UWP和windows mobile开发方面的新手,所以我做了很多研究,并设法获得具有共享内容的数据包 当您尝试检查此项时: if (this.shareOperation.Data.Contains(StandardDataFormats.Bitmap)) { this.sharedBitmapStreamRef = await this.shareOperation.Data.GetBitmapAs
if (this.shareOperation.Data.Contains(StandardDataFormats.Bitmap))
{
this.sharedBitmapStreamRef = await this.shareOperation.Data.GetBitmapAsync();
//catch (Exception ex)
//{
// NotifyUserBackgroundThread("Failed GetBitmapAsync - " + ex.Message, NotifyType.ErrorMessage);
//}
}
问题是应用程序没有将我的文件视为位图。
当我尝试获取接收到的文件类型时,它会给我System.\u COMObject。
我将get文件管理为storageitem,但无法读取IRandomAccessStreamReference。
我得到的存储项、路径、名称等
同样的事情也发生在ShareTarget示例应用程序上,它也不会将图像视为位图(formatId)。
有什么建议吗?请参考msdn上的此示例
目标应用程序:
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;
}
那么,为什么不将StorageItem加载到BitmapImage?ShareSource是否使用
数据包.SetBitmap
方法来设置数据包中包含的位图图像?如果是,ShareOperation.Data.Contains(StandardDataFormats.Bitmap)将返回true
。您还可以检查什么是StandardDataFormats类型。@IgorKulman我从gallery或文件资源管理器共享数据。我通过从IStorageItem读取路径,然后创建一个StorageFIle来加载BitmapImage。我的下一个问题是,它只在文件位于Pictures(internal storage)文件夹中时才起作用。我还添加了打开pdf的可能性。当.pdf文件位于图片文件夹中时,它会打开。我现在正在研究我需要什么权限以及如何实现文件类型关联。有什么建议吗?这一行的分界符StorageFile file=wait-StorageFile.getfilefrompathsync(filePath);使用此exeption+$exception{System.UnauthorizedAccessException:访问被拒绝。在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务任务)在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()在App1.MainPage.d_u12.MoveNext()--从引发异常的上一个位置的堆栈结束跟踪---在System.Runtime.CompilerServices.AsyncMethodBuilderCore.c.b_u6_0(对象状态),在System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()}System.UnauthorizedAccessException我现在就创建该项目,它不识别位图,只需断开所有shareoperations语句,不输出,重要的是我需要它来处理windows phoneI receive.pdf或图像对象作为System_combobject,它只将其识别为存储项。我使用创建存储文件,从路径。