简体   繁体   English

无法显示可移动SD中的图像-UWP Windows IOT

[英]Can't display image from Removeable SD - UWP Windows IOT

I have done all of the things necessary to gaining access to the files located on the SD card of my IOT device (DragonBoard 410c). 我已经完成了访问IOT设备(DragonBoard 410c)SD卡上的文件的所有必要操作。

I have all of the FileTypeAssociations 我有所有的FileTypeAssociations

    <Capability Name="internetClient" />
    <Capability Name="privateNetworkClientServer" />
    <Capability Name="internetClientServer" />
    <uap:Capability Name="userAccountInformation" />
    <uap:Capability Name="removableStorage" />
    <uap:Capability Name="enterpriseAuthentication" />

I CAN see and iterate over the files on the SD card 我可以查看并遍历SD卡上的文件

StorageFolder removablelDevices = Windows.Storage.KnownFolders.RemovableDevices;
StorageFolder sdCard = (await removablelDevices.GetFoldersAsync()).FirstOrDefault();
var files = await nm.GetFilesAsync();

foreach (var file in files)
{
    DebugText(file.Path);
    //E:\Photo1.jpg
    //E:\Photo2.jpg
}

I am setting the ImageSource of the ImageBrush of the Background to these pictures in a slideshow. 我正在幻灯片中将这些背景的ImageBrush的ImageSource设置为这些图片。

private ImageSource _CurrentPicture;
public ImageSource CurrentPicture { get { return _CurrentPicture; } set { Set(ref _CurrentPicture, value); } }

<ImageBrush  Stretch="UniformToFill" ImageSource="{x:Bind ViewModel.CurrentPicture, Mode=OneWay}"/>

The pictures do not show up (E:\\Photo1.jpg etc) 图片不显示(E:\\ Photo1.jpg等)

I AM able to iterate over fileshares on a local server during development mode, so my pictures do show on my Background in that scenario. 在开发模式下,我可以遍历本地服务器上的文件共享,因此在这种情况下,我的图片确实会显示在背景上。


I am updating the background with a DispatchTimer. 我正在使用DispatchTimer更新背景。
Now that file access is async, I am running into async hell. 现在,文件访问是异步的,我正陷入异步地狱。

public void TimerSetup()
{
    SlideShowTimer = new DispatcherTimer();
    SlideShowTimer.Tick += SlideShowTimer_Tick;
    SlideShowTimer.Interval = new TimeSpan(0, 0, SlideShowChangeIntervalSeconds);
    SlideShowTimer.Start();

}
void SlideShowTimer_Tick(object sender, object e)
{
    ChangeBackground();
}
public async Task ChangeBackground()
{
    var nextIndex = RandomGenerator.Next(0, SlideShowFiles.Length);
    var fileName = SlideShowFiles[nextIndex];
    var file = await StorageFile.GetFileFromPathAsync(fileName);
    var stream = await file.OpenAsync(FileAccessMode.Read);
    await CurPicImage.SetSourceAsync(stream);
    await Task.CompletedTask;
}

The ImageSource property on ImageBrush doesn't automatically convert file paths to ImageSource object. ImageBrush的ImageSource属性不会自动将文件路径转换为ImageSource对象。 You will have to do the conversion in your code: 您将必须在代码中进行转换:

var file = await StorageFile.GetFileFromPathAsync(@"E:\Photo1.jpg");
var stream = await file.OpenAsync(FileAccessMode.Read);
var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
imageBrush.ImageSource = bitmapImage;
await bitmapImage.SetSourceAsync(stream);

The above is the simple (quick & dirty) way to set an imagebrush from file path in code. 上面是从代码中的文件路径设置imagebrush的简单(快速且肮脏)的方法。 The more elegant way will be to implement an IValueConverter to be used in your data binding. 更为优雅的方法是实现要在数据绑定中使用的IValueConverter。 Since you want the data binding to be async and not block the UI thread there is a little bit more coding required. 由于您希望数据绑定是异步的而不是阻止UI线程,因此需要更多的编码。 The details of how to implement an async IValueConverter can be found in this excellent answer: Async Implementation of IValueConverter 可以在以下出色答案中找到有关如何实现异步IValueConverter的详细信息: IValueConverter的异步实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用自定义UWP应用程序创建Windows IoT核心映像不起作用 - Windows IoT core image creation with custom UWP application is not working 使用UWP和C#刷新图像(Raspberry Pi3 Windows10 IoT) - Refresh an image using UWP and C# (Raspberry Pi3 Windows10 IoT) UWP C#Windows IoT创建约会 - UWP C# Windows IoT Create Appointment 内存泄漏在Windows IoT上播放视频| UWP - Memory Leak playing videos on Windows IoT | UWP UWP Windows 物联网核心 Stream 路由 - UWP Windows IoT Core Stream Routing UWP:在Windows IoT上的特定坐标处模拟单击 - UWP: Simulate click at specific coordinates on Windows IoT UWP无法将目标设置为Windows 10240 - UWP can't set target to Windows 10240 如何在Raspberry PI 3的Windows 10 IoT核心版中从ASP.NET Core 2.1调用UWP函数 - How to call UWP function from ASP.NET Core 2.1 in Windows 10 IoT Core for Raspberry PI 3 UWP-Windows IOT-从USB驱动器中名为“ ad_runner”的特定文件夹中获取文件 - UWP - Windows IOT - Getting files from a specific folder named “ad_runner” located in a USB drive Windows UWP 应用程序能否连接到 websocket 服务器,从中接收数据并显示数据? - Can a Windows UWP application connect to a websocket server, receive data from it, and display the data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM