locked
Get width and height of an image taken from the pc

    Question

  • Hello,

    I have the following code to open an image from the picture library:

    FileOpenPicker opener = new FileOpenPicker();
    opener.ViewMode = PickerViewMode.Thumbnail;
    opener.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
    opener.FileTypeFilter.Add(".jpg");
    
    // Open the file picker
    file = await opener.PickSingleFileAsync();
    
    if (file != null)
    {
         // Create stream.
         var stream = await file.OpenAsync(FileAccessMode.Read);
    
         // Rewind stream to start.
         stream.Seek(0);
    
         var bpWithHDR = new BitmapImage();
         await bpWithHDR.SetSourceAsync(stream);
         img.Source = bpWithHDR;
    }

    But when I try to get for example the height:

    double h = img.Height;

    I'm getting the height of the Image control, but I want the height of the real image. How can I do that?

    Thanks.

    Thursday, May 22, 2014 9:03 PM

Answers

All replies