views:

174

answers:

1

In my Silverlight control, I am loading my background image from a stream:

   BitmapImage img = new BitmapImage();
   img.SetSource(stream);

   Image background = new Image();
   background.Source = img;

How can I find out the height of the bitmap image that was loaded from stream? None of the usual suspects (e.g., Property, DependencyProperty) seem to be available, neither on img, nor on background.

A: 

I would try:

img.Measure();
img.DesiredSize.Height;
Correl
Almost, but you got me on the right track. Here's what works for me:1. Create an event handler for the Loaded event.2. img.Measure( new Size(sizeX, sizeY));3. img.ActualHeight contains the size in pixels!
Philipp Schmid
I'm glad that I was able to help you.
Correl