BitmapImage myImage = new BitmapImage(); myImage.BeginInit(); myImage.DecodePixelWidth = 200; myImage.UriSource = new Uri("image.jpg", UriKind.Relative); myImage.EndInit();
BitmapImage myImage = new BitmapImage(); myImage.BeginInit(); myImage.CacheOption = BitmapCacheOption.OnLoad; myImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache; myImage.UriSource = new Uri("image.png", UriKind.Relative); myImage.EndInit();In this example, the CacheOption property is set to BitmapCacheOption.OnLoad to ensure that the image is fully loaded into memory and not cached on disk. The CreateOptions property is also set to BitmapCreateOptions.IgnoreImageCache to ignore any cached versions of the image. The UriSource property is again set to the location of the image file. In summary, the BitmapImage.BeginInit method is used to initialize a new instance of the BitmapImage class in C#. It is typically used to specify various options for image decoding, such as resizing or image format.