How to check if a BitmapImage instance is initialized or not? WPF

I try to use instances of the BitmapImage class in a circle, but sometimes I get error messages that the bitmap image is not initialized. How to verify that BitmapImage is initialized before using it?

+3
source share
1 answer

There are 2 Events commonly used when working with raster images, 1 fire, when the image successfully opened, and another - when the image was unsuccessful;

var myImage = new BitmapImage(new Uri(@"Images/img.jpeg",UriKind.Relative));
            myImage.ImageOpened += myImage_ImageOpened;
            myImage.ImageFailed += myImage_ImageFailed;


        void myImage_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            //handle failed event
        }

        void myImage_ImageOpened(object sender, RoutedEventArgs e)
        {
           //handle Image Opend OK event
        }
0
source

All Articles