1

I'm doing the standard CameraChooserTask dance. In my callback, I'd like to get the dimensions of the captured photo.

I tried using BitmapImage, as below, but since the BitmapImage isn't part of the render tree, I don't think it actually does any decoding (its ImageOpened event doesn't fire).

private void CameraCapture_Completed(object sender, PhotoResult e)
{
  if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
  {
    // This code DOES NOT work:
    // BitmapImage bi = new BitmapImage();
    // bi.SetSource(stream);
    // ... use bi.PixelHeight and bi.PixelWidth ...
Todd Main
  • 28,951
  • 11
  • 82
  • 146
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222

1 Answers1

2

Ah, the trick is to force someone to use the BitmapSource. By assigning it as the source for an Image, the PixelHeight and PixelWidth properties get set.

private void CameraCapture_Completed(object sender, PhotoResult e)
{
  if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
  {
    BitmapImage bi = new BitmapImage();
    bi.SetSource(stream);

    Image image = new Image();
    image.Source = bi;

    // ... use bi.PixelHeight and bi.PixelWidth ...
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222