views:

107

answers:

1

How can I get information about the source image of a WPF <Image> element?

My <Image> element has its Source bound to an ImageSource property, which changes frequently. In my code behind, I need to be able to access the actual width of the current source image file (in regular pixels), for mathematical purposes. My application will perform image operations on the image file, so this information is necessary.

Any help is appreciated.

+3  A: 

I think this may work for you:

BitmapSource sourceData = image.Source as BitmapSource;
int width = sourceData.PixelWidth;
int height = sourceData.PixelHeight;
Charlie
This is the way to do it, assuming the image source is a BitmapSource (which you totally know it is, for realz).
MojoFilter
Oh, totally. :)
Giffyguy
This worked perfectly! Thanks a ton.
Giffyguy