WPF应用程序中的自定义图形?

时间:2013-03-26 11:56:48

标签: c# wpf windows

我有一个WPF应用程序,其中有一个带有图形的图片框,我需要一种能够以简单直接的方式更改此图形的方法(如替换程序安装目录中的图像文件)。

2 个答案:

答案 0 :(得分:2)

我不确定这是不是你想要的,但是......

你可以这样做:

Source="pack://siteoforigin:,,,/Images/someimage.png"  

并使用bin / app文件夹中的图像。请查看此链接以获取更多信息...

What is application's site of origin and when to use it

答案 1 :(得分:1)

定义从外部图像文件加载图像的功能

public static ImageSource LoadImage(string fileName)
{
    BitmapImage bitmap = new BitmapImage();
    bitmap.BeginInit();
    bitmap.UriSource = new Uri("file:///" + fileName.Replace("\\", "/"));
    bitmap.EndInit();
    return bitmap;
}

然后,您可以将图像控件源指定给此函数返回值。

someImageControl.Source = LoadImage(@"d:\\images\\image.png");