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;
    }

5 comments:

  1. Thanks for that tip. I'm usually having trouble in getting the actual width and height of an image. With this code, I think I now know how to.

    web design Perth

    ReplyDelete
  2. Thanks for the code. I was having problems adjusting the width and height of an image.

    experiential marketing agency

    ReplyDelete
  3. I tried this code and it worked for some images, but it didn't work for images that are a bit big in size. Thanks for the help!

    ReplyDelete
  4. Thanks for sharing this coding for adjusting width and height of image

    ReplyDelete
  5. Thanks for the help. Sometimes a little help makes a huge difference.

    ReplyDelete