BitmapImage myImage = new BitmapImage(); myImage.BeginInit(); myImage.UriSource = new Uri("path/to/image.png"); myImage.EndInit(); myImage.Freeze(); // Freezing the bitmap image
BitmapImage myImage = new BitmapImage(); stream = new FileStream("path/to/image.png", FileMode.Open); myImage.BeginInit(); myImage.StreamSource = stream; myImage.EndInit(); myImage.Freeze(); // Freezing the bitmap imageIn this example, a new instance of the BitmapImage class is created and an image file is loaded from a stream. The Freeze method is called to prevent the image from being modified after it has been loaded. Package/Library: System.Windows.Media.Imaging