4

照片库使您能够标记人脸并为其应用标签。我知道它将标签直接插入文件中,而不是将其存储在数据库或随处的元文件中。

如果这是真的,它插入了什么数据以及它是如何格式化的?

4

2 回答 2

4

这是我想要的代码。它在 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()));
                            }

                        }
                    }
                }
            }
        }
    }
于 2009-09-27T22:17:35.037 回答
1

如果可能,Windows Live 照片库会使用XMP将元数据写入图片文件。有关详细信息,请参阅元数据和 Windows Vista 照片库

于 2009-09-25T08:44:18.607 回答