Bohrend
Bohrend

Reputation: 1497

How to detect photoresult orientation?

in windows phone how can I determine the orientation of the cameracapturetask or Photochoosertask?

   private void openCameraTask()
    {
        CameraCaptureTask cam = new CameraCaptureTask();
        cam.Completed += task_Completed;

        cam.Show();
    }

    void task_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {

            imgFrame.Visibility = System.Windows.Visibility.Visible;
            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();


            bmp.SetSource(e.ChosenPhoto);
            imgProfilePic.ImageSource = bmp;
         }
     }

Upvotes: 0

Views: 235

Answers (1)

Bruno Faria
Bruno Faria

Reputation: 5262

A possible way is by checking the height and width of the image in pixels. If the height is higher than the width then you can say it's portrait or else landscape. The BitmapImage class has no method for telling you this right away.

Something as simple as

if (bitmap.PixelHeight > bitmap.PixelWidth) {
     // portrait 
} else {
     // landscape 
}

There´s also a possibility of both sizes being the same. So there's not really a landscape or portrait in this case.

Upvotes: 1

Related Questions