JPEG "Orientation" from EXIF for automatic rotation

Is it possible to get Orientation from EXIF

I think I can get Author and other fields, but there is no property for Orientation.

JpegBitmapDecoder dec = new JpegBitmapDecoder(new Uri(""), BitmapCreateOptions.None, BitmapCacheOption.None);
string author = dec.Metadata.Author;

I want to automatically rotate my photos and I don't want to recompress JPEG. Should I do something special to achieve this or do JPEG decoder and encoder handle this for me by default

Thanks very much for any answer.
Vojta



Answer this question

JPEG "Orientation" from EXIF for automatic rotation

  • Tomas35595

    I tried all BitmapCacheOption values on January CTP and it still doesn't work :-(
  • iamajloppy

    Thank you for you answer it is very useful. Will this be included in documentation

    But now I have problem even with Author, because dec.Metadata is null. Should I do anythink else to obtain Metadata Or is this implemented in November CTP

    Thank you
    Vojta


  • Choon Meng

    Can you reply to me offline with a sample of the code you’re using



    Thanks!

  • bontan-ame

    We expose convenience properties for some common metadata properties. However, access to all of the metadata is possible. Please take a look at the BitmapMetadata object. This is a collection of all of the metadata in the file. If you wish to get the EXIF orientation, try this:



    JpegBitmapDecoder dec = new JpegBitmapDecoder(new Uri(""), BitmapCreateOptions.None, BitmapCacheOption.None);
    string author = dec.Metadata.Author;

    if (dec.Metadata.ContainsQuery(@”/app0/ifd/exif/orientation”))

    {

    Object orientation = dec.Metadata.GetQuery(@”/app0/ifd/exif/orientation”);

    }



    Robert.

  • lknm

    Try using a different BitmapCacheOption, like OnLoad. There were some issues with when and how the metadata was cached with some cache options.



    Yes, we’re working with the SDK team to get these types of things document (and hopefully with samples as well!).



    Let us know if you need any additional help,



    Robert.

  • Ildeon

    i'm seeing the same issue. _image.Metadata and _decoder.Metadata are both null.

    public class Photo
    {
    private BitmapImage _image = null;
    private BitmapDecoder _decoder = null;
    public Photo() { }
    public Photo( string path )
    {
    this.Path = path;
    }
    private string _path = "";
    public string Path
    {
    get { return _path; }
    set
    {
    _path = value;
    if(_path != "")
    {
    _image = new BitmapImage(new Uri(_path));
    _decoder = BitmapDecoder.Create(new Uri(_path),
    BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
    }
    else
    {
    _image = null;
    _decoder = null;
    }
    }
    }
    [XmlIgnore]
    public string Title
    {
    get
    {
    if(_image != null && _image.Metadata != null)
    {
    return (_image.Metadata as BitmapMetadata).Title;
    }
    return "<untitled>";
    }
    }
    [XmlIgnore]
    public string Size
    {
    get
    {
    if( _image != null )
    {
    StringBuilder sb = new StringBuilder();
    sb.Append(_image.PixelWidth);
    sb.Append(" x ");
    sb.Append(_image.PixelHeight);
    return sb.ToString();
    }
    return "unknown";
    }
    }
    [XmlIgnore]
    public string Date
    {
    get
    {
    if(_image != null && _image.Metadata != null)
    {
    return (_image.Metadata as BitmapMetadata).DateTaken;
    }
    return "unknown";
    }
    }
    [XmlIgnore]
    public string Format
    {
    get
    {
    if(_image != null && _image.Metadata != null)
    {
    return _image.Format.ToString();
    }
    return "unknown";
    }
    }
    }

  • JPEG "Orientation" from EXIF for automatic rotation