Sunday, April 4, 2010

TIPS: Get actual width and height of an Image

You can use ImageOpened event to get actual width and height of an Image like below:

        MyImage.ImageOpened += new EventHandler(Image_ImageOpened);
    }
    void Image_ImageOpened(object sender, RoutedEventArgs e)
    {
        Image img = (Image)sender;
        BitmapImage bi = (BitmapImage)img.Source;
        double width = bi.PixelWidth;
        double height = bi.PixelHeight;
    }