本文介绍了阅读“人物标签”由Windows Live照片库插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

照片库可让您标记人物的脸部并对其应用标签。据我所知,它直接将标签插入到文件中,而不是将其存储在数据库或随附的图元文件中。

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?

推荐答案

这是我想要的代码。它在C#中。

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()));
                            }

                        }
                    }
                }
            }
        }
    }

这篇关于阅读“人物标签”由Windows Live照片库插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 09:06