Reputation: 97
How can I get the size of the image url?
I tried to use:
var img = new BitmapImage(new Uri(url));
img.ImageOpened += (a, d) =>
{
Debug.WriteLine("Width: {0}, Height: {1}", img.PixelWidth, img.PixelHeight);
};
Image1.Source = img;
but it did not solve my problem.
Upvotes: 1
Views: 1044
Reputation: 9944
You should handle the ImageOpened
event of the Image
control instead:
<Image x:Name="Image1" ImageOpened="Image1_OnImageOpened" ></Image>
and get the width and the height in the handler
private void Image1_OnImageOpened(object sender, RoutedEventArgs e)
{
var width =(Image1.Source as BitmapImage).PixelWidth;
var height =(Image1.Source as BitmapImage).PixelHeight;
}
Upvotes: 2