Reading “People Tags” inserted by Windows Live Photo Gallery

。_饼干妹妹 提交于 2019-12-23 12:57:16

问题


Photo Gallery gives you the ability to mark a person's face and apply a tag to it. I understand it inserts tags directly into the file rather than store it off in a database or accompanying metafile anywhere.

So if that's true, what data is it inserting and how is it formatted?


回答1:


Here's the code I wanted. It's in C#.

        public void ReadWLPGRegions(string sourceFile)
    {
        string microsoftRegions = @"/xmp/RegionInfo/Regions";
        string microsoftPersonDisplayName = @"/PersonDisplayName";
        string microsoftRectangle = @"/Rectangle";
        BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;

        using (Stream sourceStream = File.Open(sourceFile, FileMode.Open, FileAccess.Read))
        {
            BitmapDecoder sourceDecoder = BitmapDecoder.Create(sourceStream, createOptions, BitmapCacheOption.None);

            // Check source has valid frames
            if (sourceDecoder.Frames[0] != null && sourceDecoder.Frames[0].Metadata != null)
            {
                BitmapMetadata sourceMetadata = sourceDecoder.Frames[0].Metadata as BitmapMetadata;

                // Check there is a RegionInfo
                if (sourceMetadata.ContainsQuery(microsoftRegions))
                {
                    BitmapMetadata regionsMetadata = sourceMetadata.GetQuery(microsoftRegions) as BitmapMetadata;

                    // Loop through each Region
                    foreach (string regionQuery in regionsMetadata)
                    {
                        string regionFullQuery = microsoftRegions + regionQuery;

                        // Query for all the data for this region
                        BitmapMetadata regionMetadata = sourceMetadata.GetQuery(regionFullQuery) as BitmapMetadata;

                        if (regionMetadata != null)
                        {
                            if (regionMetadata.ContainsQuery(microsoftPersonDisplayName) &&
                                regionMetadata.ContainsQuery(microsoftRectangle))
                            {
                                Console.Writeline( regionMetadata.GetQuery(microsoftRectangle).ToString()));
                                 Console.WriteLine(regionMetadata.GetQuery(microsoftPersonDisplayName).ToString()));
                            }

                        }
                    }
                }
            }
        }
    }



回答2:


When possible, Windows Live Photo Gallery uses XMP to write metadata to picture files. See Metadata and the Windows Vista Photo Gallery for details.



来源:https://stackoverflow.com/questions/1475176/reading-people-tags-inserted-by-windows-live-photo-gallery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!