問題描述
我想將我的程序從一臺電腦移到另一臺電腦,但問題是圖像沒有加載到任何其他電腦上(源問題).所以我想知道我是否可以創(chuàng)建一個放置 exe 的文件夾并將其命名為 Resources 并從那里加載每個圖像.
image2.Source = new BitmapImage(new Uri(@"Resstartoh.png"));
您可以將圖像作為資源添加到您的 Visual Studio 項目中.然后它們將被打包到可執(zhí)行文件的程序集中,您無需單獨復制它們.
在您的項目中創(chuàng)建一個文件夾(假設(shè)名為 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);
這篇關(guān)于C# WPF 從 exe 文件夾加載圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!