图片来源UriKind [英] Image source UriKind

查看:58
本文介绍了图片来源UriKind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,名称为"xx".我创建一个具有以下路径的文件夹图像":xx \ bin \ Debug \ images \

I have a project it's name is 'xx'. I create a folder "images" that have this path : xx\bin\Debug\images\

图像仅包含一张照片,名称为"1.jpg"MainWindow包含Image控件;我设置了此代码以加载图像源,但是为什么??:

images contain only one photo it's name is "1.jpg" the MainWindow contain Image control; I set this code to load the image source but it doesn't work why ??:

private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
    Image i = sender as Image; ;
    BitmapImage b = new BitmapImage(new Uri(@"images\1.jpg",UriKind.Relative));
    i.Source=b;
}

如何通过代码加载图像源?在此先感谢:)

How can I load the Image source by code ?? Thanks in advance :)

推荐答案

您需要在 images 文件夹和 1.jpg 的属性设置为资源.要加载资源,请使用 packURI 约定.

You need to add 1.jpg to your project in the images folder and set the Properties of 1.jpg to Resource. To load the resource, use the packURI conventions.

private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
    Image i = sender as Image; ;
    BitmapImage b = new BitmapImage(new Uri(@"pack://application:,,,/" 
         + Assembly.GetExecutingAssembly().GetName().Name 
         + ";component/" 
         + "Images/1.jpg", UriKind.Absolute)); 
    i.Source=b;
}

这篇关于图片来源UriKind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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