UWP如何显示网络目录中的图像

编程入门 行业动态 更新时间:2024-10-23 01:35:33
本文介绍了UWP如何显示网络目录中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试了多种方法将图像源设置为UWP应用程序中的网络目录.例如,我尝试过以下示例:

I have tried many ways to set image source to a network directory in my UWP application. For example I have tried this example:

BitmapImage bitmap = new BitmapImage(new Uri(@"\\venera\Mariner\747\03_WEDNESDAY\003\00 Flat B -\APR3783216-MED-BLK TAPE-GB-Apron.jpg")); UserImage.Source = bitmap;

bitmap.UriSource = new Uri(@"\\venera\Mariner\747\03_WEDNESDAY\003\00 Flat B -\APR3783216-MED-BLK TAPE-GB-Apron.jpg", UriKind.Absolute); UserImage.Source = bitmap;

但是它们都不起作用.我最终遇到以下错误E_NETWORK_ERROR,我已经从stackoverflow和其他资源中读取了很多链接,但是没有任何适合我的东西.

But none of them works. I ended up with the following error E_NETWORK_ERROR I have read many links from stackoverflow and from other resource but there is not any thing which works for me.

我已经设置了必需的功能和声明.

I have set required capabilities and declarations for it.

我已经尝试过使用Windows.Storage.Pickers.FolderPicker进行尝试,但是找不到任何可以设置读取文件位置的文件夹. 我不想打开文件夹选择器,我只想直接从网络的指定位置获取图像.

I have tried it with Windows.Storage.Pickers.FolderPicker but I couldn't find any thing where I can set the folder location where to read files. I don want to open folder picker, I just want to get images directly from a specified location of network.

可能有些人试图将其与此票证相关如何在Windows Universal应用程序中显示网络文件夹或本地驱动器中的图像 但这对我的工作没有帮助.

May be some you try to relate it with this ticket How to display an image from a network folder or local drive in a Windows Universal App but this is not helping me in my task.

我也为我尝试过以下示例,但仍无法实现目标: docs.microsoft/zh-CN/windows/uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries

I also have tried these examples for me but still couldn't achieve the target: docs.microsoft/en-us/windows/uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries

docs.microsoft /en-us/uwp/api/windows.ui.xaml.controls.image

我遇到System.UnauthorizedAccessException: 'Access is denied.错误

推荐答案

要在网络上的共享文件夹中设置.jpg文件,我们可以先获取StorageFile,然后使用SetSource方法将源设置为BitmapImage.要访问共享文件夹中的文件,我们需要在应用清单中声明一些功能.

To set a .jpg file in shared folder on network, we can get the StorageFile first and then use the SetSource method to set the source to the BitmapImage. To access files in the shared folder, we need declare some capabilities in the app manifest.

通用命名约定(UNC)是Microsoft Windows中常用于访问共享网络文件夹的命名系统.有关更多信息,请参考文件访问权限.

Universal Naming Convention (UNC) is the naming system commonly used in Microsoft Windows for accessing shared network folders. For more info, please refer File access permissions.

这是我的Package.appxmanifest:

This is my Package.appxmanifest:

<Applications> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="UWP_how_to_show_image_from_a_network.App"> <uap:VisualElements DisplayName="UWP how to show image from a network" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="UWP how to show image from a network" BackgroundColor="transparent"> <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"> </uap:DefaultTile> <uap:SplashScreen Image="Assets\SplashScreen.png" /> </uap:VisualElements> <Extensions> <uap:Extension Category="windows.fileTypeAssociation"> <uap:FileTypeAssociation Name="mypictest"> <uap:DisplayName>MyPicTest</uap:DisplayName> <uap:SupportedFileTypes> <uap:FileType>.jpg</uap:FileType> </uap:SupportedFileTypes> </uap:FileTypeAssociation> </uap:Extension> </Extensions> </Application> </Applications> <Capabilities> <Capability Name="internetClient" /> <Capability Name="privateNetworkClientServer" /> <Capability Name="internetClientServer" /> <uap:Capability Name="enterpriseAuthentication" /> </Capabilities>

设置BitmapImage的代码:

The code of setting BitmapImage:

StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(@"\\venera\Mariner\747\03_WEDNESDAY\003\00 Flat B -"); StorageFile file = await folder.GetFileAsync("APR3783216-MED-BLK TAPE-GB-Apron.jpg"); using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)){ BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(stream); UserImage.Source = bitmap; }

更多推荐

UWP如何显示网络目录中的图像

本文发布于:2023-11-02 08:20:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   目录中   网络   UWP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!