wpf-images

Image is a base abstract class representing images in GDI+. Bitmap is a concrete implementation of this base class.

BitmapImage is a way to represent an image in a vector based GUI engine like WPF and Silverlight. Contrary to a Bitmap, it is not based on GDI+. It is based on the Windows Imaging Component.

msdn

<!-- Simple image rendering. However, rendering an image this way may not
result in the best use of application memory. See markup below which
creates the same end result but using less memory. -->
<Image Width="200"
Source="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg"/>

<Image Width="200">
<Image.Source>
<!-- To save significant application memory, set the DecodePixelWidth or
DecodePixelHeight of the BitmapImage value of the image source to the desired
height and width of the rendered image. If you don't do this, the application will
cache the image as though it were rendered as its normal size rather then just
the size that is displayed. -->
<!-- Note: In order to preserve aspect ratio, only set either DecodePixelWidth
or DecodePixelHeight but not both. -->
<BitmapImage DecodePixelWidth="200"
UriSource="C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg" />
</Image.Source>
</Image>

使用图片资源

<Window x:Class="fwPlcCheckAssist.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
...
Title="fwPlcCheckAssist-2021.03.16 1023" Height="800" Width="1000">
<Window.Resources>
<BitmapImage x:Key="img_black" UriSource="img/black-48.png" DecodePixelWidth="48" />
<BitmapImage x:Key="img_green" UriSource="img/green-48.png" DecodePixelWidth="48" />
<BitmapImage x:Key="img_red" UriSource="img/red-48.png" DecodePixelWidth="24" />
<BitmapImage x:Key="img_black24" UriSource="img/black-48.png" DecodePixelWidth="24" />
</Window.Resources>
<Grid>
...
</Grid>

img_next.Source = FindResource("img_red") as BitmapImage;