无法在C#WPF中从资源到图像框添加图像 [英] Can not add a image from resource to image box in C# WPF

查看:56
本文介绍了无法在C#WPF中从资源到图像框添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时尝试将资源文件夹中的图像添加到图像框中,如果我在不参考资源文件的情况下提供图像的完整URl,那么该怎么办



我尝试过:



ImageSource imageSource = new BitmapImage(new Uri(@Images) / Icon Set / CloudyDay.jpg,UriKind.Relative));



imgwicon.Source = imageSource;

im trying to add a image from resource folder to a image box, how ever if i gave the full URl of the image without referring to the resource file it is working

What I have tried:

ImageSource imageSource = new BitmapImage(new Uri(@"Images/Icon Set/CloudyDay.jpg", UriKind.Relative));

imgwicon.Source = imageSource;

推荐答案

指定要在Image控件中使用的图像的路径的最简单方法是执行以下操作:



1.将图像嵌入为项目中的二进制资源

2.将图像的构建操作设置为资源

3.只需使用文件名作为图像的源(如果在子文件夹中,则为前缀路径)

4.不要用你的可执行文件分发图像(它是嵌入的)



只需使用图片标签中的文件名:

The easiest way to specify a path to an image to be used in an Image control is to do the following:

1. Embed the image as a binary resource in your project
2. Set the Build Action of the image to Resource
3. Just use the filename as the image’s Source (prefix path if in subfolder)
4. Do not distribute the image with your executable (it’s embedded)

Just use the filename in the Image tag:
<Image Source="CloudyDay.jpg"/>



使用路径:


With path:.

<Image Source="Images/Icon Set/CloudyDay.jpg"/>


ImageSource imageSource = new BitmapImage(new Uri(@"Images/Icon Set/CloudyDay.jpg", UriKind.Relative));

imgwicon.Source = imageSource;





这里删除,



here remove the ,

UriKind.Relative





这就是全部!



thats all!


这篇关于无法在C#WPF中从资源到图像框添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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