Question

I write some Windows Phone 7 APPs. I intend to visit the photo on cell phone. I take a photo with the phone and the size of photo is 1944x2592 (W x H). Then I use

MediaLibrary mediaLibrary = new MediaLibrary();
for (int x = 0; x < mediaLibrary.Pictures.Count; ++x)
{
    Picture pic = mediaLibrary.Pictures[x];
    int w = pic.width;
    int h = pic.height;
    ...

However, I found that the w is 2592 and the h is 1944. The value of Width and Height are reversed! Who can tell me what's going on? what's the problem? I am looking forward to your reply! Thank you.

Was it helpful?

Solution

The camera detects the phone's orientation and stores it as metadata. So the height and width will always be the same, and the orientation when displayed in Zune, Picture Viewer, or most other programs will be read out of the metadata.

Here is a resource explaining it and providing sample code in C#. The particularly important part is right at the bottom. To use this, you will need this library (also a useful guide there):

void OnCameraCaptureCompleted(object sender, PhotoResult e)
{
   // figure out the orientation from EXIF data
   e.ChosenPhoto.Position = 0;
   JpegInfo info = ExifReader.ReadJpeg(e.ChosenPhoto, e.OriginalFileName);

   _width = info.Width;
   _height = info.Height;
   _orientation = info.Orientation;

   PostedUri.Text = info.Orientation.ToString();

   switch (info.Orientation)
   {
       case ExifOrientation.TopLeft:
       case ExifOrientation.Undefined:
           _angle = 0;
           break;
       case ExifOrientation.TopRight:
           _angle = 90;
           break;
       case ExifOrientation.BottomRight:
           _angle = 180;
           break;
       case ExifOrientation.BottomLeft:
           _angle = 270;
           break;
   }

   .....

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top