如何从文件位置WPF添加图像 [英] how to add images from file location WPF

查看:28
本文介绍了如何从文件位置WPF添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从WPF中的文件位置加载图像.

Am stuck to load images from my file location in WPF.

这是我的xaml

<Image Grid.ColumnSpan="3" Grid.Row="11" Height="14" HorizontalAlignment="Left" Margin="57,1,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="108" />

这是我的代码后面

internal int FindImages(string slugName, DirectoryInfo outputFolder)
{
    if (slugName != null)
    {
        List<string> filePathList = Directory.GetFiles(outputFolder.FullName).ToList();
        List<string> filePathList_ToBeDeleted = new List<string>();
        foreach (string filePath in filePathList)
        {                  
            if (Path.GetFileNameWithoutExtension(filePath).ToLower().Contains("_70x70"))
            {                           
                image1.Source = filePath;
            }                   
        }
        int count = 0;

        return count;
    }

我的文件路径显示为"\\\\ Server1 \\ Dev \\ Online \\ Images \\ 7 PMa_Test3_0306_70x70.jpg"

推荐答案

这就是陷阱

image1.Source = new BitmapImage(new Uri(filePath));

这篇关于如何从文件位置WPF添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆