C# WPF 从 exe 文件夹加载图像

C# WPF Load images from the exe folder(C# WPF 从 exe 文件夹加载图像)
本文介绍了C# WPF 从 exe 文件夹加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想将我的程序从一台电脑移到另一台电脑,但问题是图像没有加载到任何其他电脑上(源问题).所以我想知道我是否可以创建一个放置 exe 的文件夹并将其命名为 Resources 并从那里加载每个图像.

image2.Source = new BitmapImage(new Uri(@"Resstartoh.png"));

解决方案

您可以将图像作为资源添加到您的 Visual Studio 项目中.然后它们将被打包到可执行文件的程序集中,您无需单独复制它们.

在您的项目中创建一个文件夹(假设名为 Images)并将您的图像添加到该文件夹中.

确保图像的:

var uri = new Uri("pack://application:,,,/Images/SomeImage.png");image.Source = new BitmapImage(uri);

i want to move my program from a pc to another but the problem is the images are not loaded on any other pc (Source problem) . So i was wondering if i could just create a folder where the exe is placed and name it Resources and to load every image from there.

image2.Source = new BitmapImage(new Uri(@"Resstartoh.png"));

解决方案

You may just add the images as resources to your Visual Studio project. Then they will be packed into the assembly of the executable and you don't need to copy them separately.

Create a folder in your project (let's say called Images) and add your images to that folder.

Make sure that the Build Action for the images is set to Resource.

Now you can simply create a BitmapImage from such a resource by an appropriate Pack URI:

var uri = new Uri("pack://application:,,,/Images/SomeImage.png");
image.Source = new BitmapImage(uri);

这篇关于C# WPF 从 exe 文件夹加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
Query From LDAP for User Groups(从 LDAP 查询用户组)
How can I get DOMAINUSER from an AD DirectoryEntry?(如何从 AD DirectoryEntry 获取 DOMAINUSER?)