WPF应用程序中的自定义图形? [英] Custom graphic in WPF application?
本文介绍了WPF应用程序中的自定义图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 WPF 应用程序,其中有一个带有图形的图片框,我需要一种能够以简单直接的方式更改此图形的方法(例如替换程序安装目录中的图像文件).>
I have a WPF application which has a picture box with a graphic in it, I need a way to be able to change this graphic in a simple straightforward manner (like replacing an image file in the programs install directory).
推荐答案
定义一个从外部图像文件加载图像的函数
Define a function that loads an image from an external image file
public static ImageSource LoadImage(string fileName)
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri("file:///" + fileName.Replace("\\", "/"));
bitmap.EndInit();
return bitmap;
}
然后您可以为该函数的返回值分配一个图像控件源.
You can then assign an image controls source to this functions return value.
someImageControl.Source = LoadImage(@"d:\\images\\image.png");
这篇关于WPF应用程序中的自定义图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文