private static AvifMetadata CreateAvifMetadata(Document doc) { byte[] exifBytes = null; byte[] iccProfileBytes = null; byte[] xmpBytes = null; Dictionary <MetadataKey, MetadataEntry> exifMetadata = GetExifMetadataFromDocument(doc); if (exifMetadata != null) { Exif.ExifColorSpace exifColorSpace = Exif.ExifColorSpace.Srgb; MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile; if (exifMetadata.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem)) { iccProfileBytes = iccProfileItem.GetData(); exifMetadata.Remove(iccProfileKey); exifColorSpace = Exif.ExifColorSpace.Uncalibrated; } exifBytes = new ExifWriter(doc, exifMetadata, exifColorSpace).CreateExifBlob(); } XmpPacket xmpPacket = doc.Metadata.TryGetXmpPacket(); if (xmpPacket != null) { string packetAsString = xmpPacket.ToString(XmpPacketWrapperType.ReadOnly); xmpBytes = System.Text.Encoding.UTF8.GetBytes(packetAsString); } return(new AvifMetadata(exifBytes, iccProfileBytes, xmpBytes)); }
/// <summary> /// Reads Id3 metadata directly in MP3 format /// </summary> public static void ReadId3MetadataDirectly() { //ExStart:ReadId3MetadataInMp3Directly // init Mp3Format class Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath)); // read album in ID3 v1 MetadataProperty album = mp3Format[MetadataKey.Id3v1.Album]; Console.WriteLine(album); // read title in ID3 v2 MetadataProperty title = mp3Format[MetadataKey.Id3v2.Title]; Console.WriteLine(title); // create custom ID3v2 key // TCOP is used for 'Copyright' property according to the ID3 specification MetadataKey copyrightKey = new MetadataKey(MetadataType.Id3v2, "TCOP"); // read copyright property MetadataProperty copyright = mp3Format[copyrightKey]; Console.WriteLine(copyright); //ExEnd:ReadId3MetadataInMp3Directly }
private async Task DeleteSamples(Measure measure) { if (_suppressed) { return; } var predicate = HKQuery.GetPredicateForMetadataKey( HKMetadataKey.ExternalUuid, new[] { NSObject.FromObject(MetadataKey.GetExternalUUID(measure.Id)) }); var result = await _healthStore.DeleteObjectsAsync( HKQuantityType.Create(HKQuantityTypeIdentifier.BloodGlucose), predicate); if (!result.Item1) { _log.Warn($"Can't delete blood glucose data by reason: {result.Item2.LocalizedDescription}"); } result = await _healthStore.DeleteObjectsAsync( HKQuantityType.Create(HKQuantityTypeIdentifier.InsulinDelivery), predicate); if (!result.Item1) { _log.Warn($"Can't delete insulin data by reason: {result.Item2.LocalizedDescription}"); } }
private static HKQuantitySample CreateInsulinHKSample( int measureId, DateTime date, int version, InsulinType type, int value ) { var metadata = new NSDictionary( MetadataKey.DiabettoOrigin, NSObject.FromObject(true), HKMetadataKey.InsulinDeliveryReason, NSObject.FromObject( type == InsulinType.Basal ? HKInsulinDeliveryReason.Basal : HKInsulinDeliveryReason.Bolus), HKMetadataKey.TimeZone, NSObject.FromObject("UTC"), HKMetadataKey.ExternalUuid, NSObject.FromObject(MetadataKey.GetExternalUUID(measureId)), HKMetadataKey.WasUserEntered, NSObject.FromObject(true), HKMetadataKey.SyncVersion, NSObject.FromObject(version), HKMetadataKey.SyncIdentifier, NSObject.FromObject(MetadataKey.GetInsulinIdentifier(measureId, type))); return(HKQuantitySample.FromType( HKQuantityType.Create(HKQuantityTypeIdentifier.InsulinDelivery), HKQuantity.FromQuantity(HKUnit.InternationalUnit, value), (NSDate)date, (NSDate)date, metadata)); }
private static HKQuantitySample CreateBloodGlucoseHKSample( int measureId, DateTime date, int version, int level ) { var metadata = new NSDictionary( MetadataKey.DiabettoOrigin, NSObject.FromObject(true), HKMetadataKey.TimeZone, NSObject.FromObject("UTC"), HKMetadataKey.SyncVersion, NSObject.FromObject(version), HKMetadataKey.WasUserEntered, NSObject.FromObject(true), HKMetadataKey.ExternalUuid, NSObject.FromObject(MetadataKey.GetExternalUUID(measureId)), HKMetadataKey.SyncIdentifier, NSObject.FromObject(MetadataKey.GetBloodGlucoseIdentifier(measureId))); return(HKQuantitySample.FromType( HKQuantityType.Create(HKQuantityTypeIdentifier.BloodGlucose), HKQuantity.FromQuantity( HKUnit .CreateMoleUnit(HKMetricPrefix.Milli, HKUnit.MolarMassBloodGlucose) .UnitDividedBy(HKUnit.Liter), level / 10.0), (NSDate)date, (NSDate)date, metadata)); }
public Task <BlobObject> GetBlobAsync(BlobName name, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <BlobObject>(cancellationToken)); } var file = new FileInfo(Path.Combine(_directory.FullName, FileName.From(name))); if (!file.Exists) { return(Task.FromResult <BlobObject>(null)); } using (var fileStream = file.OpenRead()) using (var reader = new BinaryReader(fileStream, Encoding.UTF8)) { var metadata = Metadata.None; var contentType = ContentType.Parse(reader.ReadString()); var metadatumCount = reader.ReadInt32(); for (var index = 0; index < metadatumCount; index++) { var key = new MetadataKey(reader.ReadString()); var valueLength = reader.ReadInt32(); var value = valueLength != -1 ? reader.ReadString() : null; metadata = metadata.Add(new KeyValuePair <MetadataKey, string>(key, value)); } return(Task.FromResult(new BlobObject(name, metadata, contentType, contentCancellationToken => { if (!File.Exists(file.FullName)) { throw new BlobNotFoundException(name); } var contentFileStream = file.OpenRead(); using (var contentReader = new BinaryReader(contentFileStream, Encoding.UTF8, true)) { // skip over the metadata contentReader.ReadString(); var contentMetadatumCount = contentReader.ReadInt32(); for (var index = 0; index < contentMetadatumCount; index++) { contentReader.ReadString(); var valueLength = contentReader.ReadInt32(); if (valueLength != -1) { contentReader.ReadString(); } } } return Task.FromResult <Stream>(new ForwardOnlyStream(contentFileStream)); }))); } }
private void EnrichWith(IMessage message, MetadataKey key, string value) { var metadata = message.Metadata; if (metadata.ContainsKey(key)) { metadata.Remove(key); } metadata.Add(key, value); }
private static Dictionary <MetadataKey, MetadataEntry> GetExifMetadataFromDocument(Document doc) { Dictionary <MetadataKey, MetadataEntry> items = null; Metadata metadata = doc.Metadata; ExifPropertyItem[] exifProperties = metadata.GetExifPropertyItems(); if (exifProperties.Length > 0) { items = new Dictionary <MetadataKey, MetadataEntry>(exifProperties.Length); foreach (ExifPropertyItem property in exifProperties) { MetadataSection section; switch (property.Path.Section) { case ExifSection.Image: section = MetadataSection.Image; break; case ExifSection.Photo: section = MetadataSection.Exif; break; case ExifSection.Interop: section = MetadataSection.Interop; break; case ExifSection.GpsInfo: section = MetadataSection.Gps; break; default: throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Unexpected {0} type: {1}", nameof(ExifSection), (int)property.Path.Section)); } MetadataKey metadataKey = new MetadataKey(section, property.Path.TagID); if (!items.ContainsKey(metadataKey)) { byte[] clonedData = PaintDotNet.Collections.EnumerableExtensions.ToArrayEx(property.Value.Data); items.Add(metadataKey, new MetadataEntry(metadataKey, (TagDataType)property.Value.Type, clonedData)); } } } return(items); }
public void TestCreation() { const string DBPath = "test1.db"; if (File.Exists(DBPath)) { File.Delete(DBPath); } using (var provider = new QueryMetadataProvider()) { const string TestKey = "TestKey"; const string TestUrl = "a/test/url"; const string TestValue = "test value"; // Create database bool result = provider.Create(DBPath); Assert.True(result); // Add a key and retrieve it result = provider.AddKey(new MetadataKey(TestKey, MetadataKey.DatabaseType.String)); Assert.True(result); IEnumerable <MetadataKey> fetchedKeys = provider.FetchAllKeys(); Assert.NotNull(fetchedKeys); Assert.AreEqual(fetchedKeys.Count(), 1); MetadataKey key = fetchedKeys.First(); Assert.NotNull(key); Assert.AreEqual(key.Name, TestKey); Assert.AreEqual(key.Type, MetadataKey.DatabaseType.String); // Add a metadata and retrieve it var stringMetadata = new ObjectMetadata <string>(TestUrl, key, TestValue); result = provider.Write(stringMetadata); Assert.True(result); IEnumerable <string> fetchedUrls = provider.FetchAllObjectUrls(); Assert.NotNull(fetchedUrls); Assert.AreEqual(fetchedUrls.Count(), 1); string url = fetchedUrls.First(); Assert.AreEqual(url, TestUrl); IEnumerable <IObjectMetadata> metadata = provider.Fetch(url); Assert.NotNull(metadata); Assert.AreEqual(metadata.Count(), 1); IObjectMetadata metadatum = metadata.First(); Assert.AreEqual(metadatum.Key, key); Assert.AreEqual(metadatum.ObjectUrl, TestUrl); Assert.AreEqual(metadatum.Value, TestValue); provider.Close(); } }
public void TestBuilder() { Utils.CleanContext(); if (File.Exists(QueryMetadataProvider.DefaultDatabaseFilename)) { File.Delete(QueryMetadataProvider.DefaultDatabaseFilename); } using (var provider = new QueryMetadataProvider()) { const string TestStringKeyName = "TestString"; const string TestFloatKeyName = "TestFloat"; var testStringKey = new MetadataKey(TestStringKeyName, MetadataKey.DatabaseType.String); var testFloatKey = new MetadataKey(TestFloatKeyName, MetadataKey.DatabaseType.Float); // Create database bool result = provider.Create(QueryMetadataProvider.DefaultDatabaseFilename); Assert.True(result); // Add a key and retrieve it provider.AddKey(testStringKey); provider.AddKey(testFloatKey); provider.Write(new ObjectMetadata("/assets/${PathVariable}/url1", testStringKey, "Test1")); provider.Write(new ObjectMetadata("/assets/${PathVariable}/url2", testStringKey, "Test2")); provider.Write(new ObjectMetadata("/assets/${PathVariable}/url3", testFloatKey, 42.69f)); } var builder = Utils.CreateBuilder(); var commands = new List <Command>(); builder.MetadataDatabaseDirectory = "./"; builder.InitialVariables.Add("PathVariable".ToUpperInvariant(), "path/via/variable"); commands.Add(new EchoCommand("/assets/${PathVariable}/url1", "Metadata TestString: (${Metadata:TestString})")); commands.Add(new EchoCommand("/assets/${PathVariable}/url2", "Metadata TestString: (${Metadata:TestString})")); commands.Add(new EchoCommand("/assets/${PathVariable}/url3", "Metadata TestFloat: (${Metadata:TestFloat})")); commands.Add(new EchoCommand("/assets/${PathVariable}/url4", "Non existing metadata: (${Metadata:NonExisting})")); builder.Root.Add(commands); builder.Run(Builder.Mode.Build); Assert.That(((EchoCommand)commands[0]).Echo, Is.EqualTo("Metadata TestString: (Test1)")); Assert.That(((EchoCommand)commands[1]).Echo, Is.EqualTo("Metadata TestString: (Test2)")); Assert.That(((EchoCommand)commands[2]).Echo, Is.EqualTo("Metadata TestFloat: (" + 42.69f + ")")); Assert.That(((EchoCommand)commands[3]).Echo, Is.EqualTo("Non existing metadata: ()")); }
private async Task EditMeasure(Measure measure) { if (_suppressed) { return; } if (!measure.Level.HasValue) { var predicate = HKQuery.GetPredicateForMetadataKey( HKMetadataKey.ExternalUuid, new[] { NSObject.FromObject(MetadataKey.GetExternalUUID(measure.Id)) }); await _healthStore.DeleteObjectsAsync( HKQuantityType.Create(HKQuantityTypeIdentifier.BloodGlucose), predicate); } var samples = GetQuantitySamples(measure); await AddSamples(samples); }
public void TestBuilder() { Utils.CleanContext(); if (File.Exists(QueryMetadataProvider.DefaultDatabaseFilename)) File.Delete(QueryMetadataProvider.DefaultDatabaseFilename); using (var provider = new QueryMetadataProvider()) { const string TestStringKeyName = "TestString"; const string TestFloatKeyName = "TestFloat"; var testStringKey = new MetadataKey(TestStringKeyName, MetadataKey.DatabaseType.String); var testFloatKey = new MetadataKey(TestFloatKeyName, MetadataKey.DatabaseType.Float); // Create database bool result = provider.Create(QueryMetadataProvider.DefaultDatabaseFilename); Assert.True(result); // Add a key and retrieve it provider.AddKey(testStringKey); provider.AddKey(testFloatKey); provider.Write(new ObjectMetadata("/assets/${PathVariable}/url1", testStringKey, "Test1")); provider.Write(new ObjectMetadata("/assets/${PathVariable}/url2", testStringKey, "Test2")); provider.Write(new ObjectMetadata("/assets/${PathVariable}/url3", testFloatKey, 42.69f)); } var builder = Utils.CreateBuilder(); var commands = new List<Command>(); builder.MetadataDatabaseDirectory = "./"; builder.InitialVariables.Add("PathVariable".ToUpperInvariant(), "path/via/variable"); commands.Add(new EchoCommand("/assets/${PathVariable}/url1", "Metadata TestString: (${Metadata:TestString})")); commands.Add(new EchoCommand("/assets/${PathVariable}/url2", "Metadata TestString: (${Metadata:TestString})")); commands.Add(new EchoCommand("/assets/${PathVariable}/url3", "Metadata TestFloat: (${Metadata:TestFloat})")); commands.Add(new EchoCommand("/assets/${PathVariable}/url4", "Non existing metadata: (${Metadata:NonExisting})")); builder.Root.Add(commands); builder.Run(Builder.Mode.Build); Assert.That(((EchoCommand)commands[0]).Echo, Is.EqualTo("Metadata TestString: (Test1)")); Assert.That(((EchoCommand)commands[1]).Echo, Is.EqualTo("Metadata TestString: (Test2)")); Assert.That(((EchoCommand)commands[2]).Echo, Is.EqualTo("Metadata TestFloat: (" + 42.69f + ")")); Assert.That(((EchoCommand)commands[3]).Echo, Is.EqualTo("Non existing metadata: ()")); }
public ObjectMetadata(string owner, MetadataKey key) { ObjectUrl = owner; Key = key; Value = key.GetDefaultValue(); }
public Task<IEnumerable<IObjectMetadata>> FetchAsync(MetadataKey key) { return Task.Run(() => Fetch(key)); }
public override void setMetadataStatus(MetadataKey metadataKey, MetadataStatus metadataStatus) { Log.v(TAG, "setMetadataStatus: " + metadataKey + ", " + metadataStatus); }
public IEnumerable<MetadataKey> FetchAllKeys() { var keysToRemove = new List<MetadataKey>(keyIds.Keys); const string Query = @"SELECT * FROM `Keys`"; DataTable dataTable = ExecuteReader(Query); foreach (DataRow row in dataTable.Rows) { var typeId = (int)(long)row["TypeId"]; var keyId = (long)row["KeyId"]; if (typeId >= 0 && typeId < Enum.GetValues(typeof(MetadataKey.DatabaseType)).Length) { var key = new MetadataKey((string)row["Name"], (MetadataKey.DatabaseType)typeId); keyIds[key] = keyId; keysToRemove.Remove(key); } } // Also remove keys that has been removed foreach (var key in keysToRemove) { keyIds.Remove(key); } return keyIds.Keys.ToArray(); }
public bool RemoveKey(MetadataKey key) { if (key == null) throw new ArgumentNullException("key"); if (!key.IsValid()) throw new ArgumentException(@"Key is invalid.", "key"); var typeId = (int)key.Type; if (typeId != -1) { lock (lockObject) { if (connection != null) { string query = String.Format(@"DELETE FROM `Keys` WHERE `Keys`.`TypeId` = '{0}' AND `Keys`.`Name` = '{1}'", typeId, key.Name); return ExecuteNonQuery(query) == 1; } } } return false; }
public bool AddKey(MetadataKey key) { if (key == null) throw new ArgumentNullException("key"); if (!key.IsValid()) throw new ArgumentException(@"Key is invalid.", "key"); var typeId = (int)key.Type; if (typeId != -1) { lock (lockObject) { if (connection != null) { // TODO/Benlitz: a transaction that first try to fetch the key. If it exists, it should return false string query = String.Format(@"INSERT INTO `Keys` (`TypeId`, `Name`) VALUES ('{0}', '{1}')", typeId, key.Name); return ExecuteNonQuery(query) == 1; } } } return false; }
private IEnumerable<IObjectMetadata> ParseResult(DataTable dataTable) { var result = new List<IObjectMetadata>(); foreach (DataRow row in dataTable.Rows) { var url = (string)row["Location"]; var name = (string)row["Name"]; var type = (MetadataKey.DatabaseType)(long)row["TypeId"]; var key = new MetadataKey(name, type); var keyId = (long)row["KeyId"]; var objectUrlId = (long)row["ObjectUrlId"]; keyIds[key] = keyId; objectUrlIds[FormatUrl(url)] = objectUrlId; object value = key.ConvertValue(row["Value"].ToString()); result.Add(new ObjectMetadata(url, key, value)); } return result; }
public Task<IObjectMetadata> FetchAsync(string objectUrl, MetadataKey key) { return Task.Run(() => Fetch(objectUrl, key)); }
public IObjectMetadata Fetch(string objectUrl, MetadataKey key) { string query = String.Format(@"SELECT * FROM `Metadata` INNER JOIN ObjectUrls ON `ObjectUrls`.`ObjectUrlId` = `Metadata`.`ObjectUrlId` INNER JOIN Keys ON `Keys`.`KeyId` = `Metadata`.`KeyId` WHERE `ObjectUrls`.`Location` = '{0}' AND `Keys`.`Name` = '{1}' AND `Keys`.`TypeId` = '{2}'", FormatUrl(objectUrl), key.Name, (int)key.Type); return ParseResult(ExecuteReader(query)).SingleOrDefault(); }
public ObjectMetadata(string owner, MetadataKey key) { ObjectUrl = owner; Key = key; Value = key.GetDefaultValue(); }
public ObjectMetadata(string owner, MetadataKey key, object value) { ObjectUrl = owner; Key = key; Value = value; }
public ObjectMetadata(string owner, MetadataKey key, object value) { ObjectUrl = owner; Key = key; Value = value; }
private static WebPNative.MetadataParams CreateWebPMetadata(Document doc, Surface scratchSurface) { byte[] iccProfileBytes = null; byte[] exifBytes = null; byte[] xmpBytes = null; string colorProfile = doc.Metadata.GetUserValue(WebPMetadataNames.ColorProfile); if (!string.IsNullOrEmpty(colorProfile)) { iccProfileBytes = Convert.FromBase64String(colorProfile); } string exif = doc.Metadata.GetUserValue(WebPMetadataNames.EXIF); if (!string.IsNullOrEmpty(exif)) { exifBytes = Convert.FromBase64String(exif); } string xmp = doc.Metadata.GetUserValue(WebPMetadataNames.XMP); if (!string.IsNullOrEmpty(xmp)) { xmpBytes = Convert.FromBase64String(xmp); } if (iccProfileBytes == null || exifBytes == null) { Dictionary <MetadataKey, MetadataEntry> propertyItems = GetMetadataFromDocument(doc); if (propertyItems != null) { ExifColorSpace exifColorSpace = ExifColorSpace.Srgb; if (iccProfileBytes != null) { exifColorSpace = ExifColorSpace.Uncalibrated; } else { MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile; if (propertyItems.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem)) { iccProfileBytes = iccProfileItem.GetData(); propertyItems.Remove(iccProfileKey); exifColorSpace = ExifColorSpace.Uncalibrated; } } if (exifBytes == null) { exifBytes = new ExifWriter(doc, propertyItems, exifColorSpace).CreateExifBlob(); } } } if (iccProfileBytes != null || exifBytes != null || xmpBytes != null) { return(new WebPNative.MetadataParams(iccProfileBytes, exifBytes, xmpBytes)); } return(null); }
private static Dictionary <MetadataKey, MetadataEntry> GetMetadataFromDocument(Document doc) { Dictionary <MetadataKey, MetadataEntry> items = null; Metadata metadata = doc.Metadata; #if PDN_3_5_X string[] exifKeys = metadata.GetKeys(Metadata.ExifSectionName); if (exifKeys.Length > 0) { items = new Dictionary <MetadataKey, MetadataEntry>(exifKeys.Length); foreach (string key in exifKeys) { string blob = metadata.GetValue(Metadata.ExifSectionName, key); try { PropertyItem pi = PaintDotNet.SystemLayer.PdnGraphics.DeserializePropertyItem(blob); MetadataKey metadataKey = new MetadataKey(ExifTagHelper.GuessTagSection(pi), (ushort)pi.Id); if (!items.ContainsKey(metadataKey)) { items.Add(metadataKey, new MetadataEntry(metadataKey, (TagDataType)pi.Type, pi.Value)); } } catch { // Ignore any items that cannot be deserialized. } } } #else PaintDotNet.Imaging.ExifPropertyItem[] exifProperties = metadata.GetExifPropertyItems(); if (exifProperties.Length > 0) { items = new Dictionary <MetadataKey, MetadataEntry>(exifProperties.Length); foreach (PaintDotNet.Imaging.ExifPropertyItem property in exifProperties) { MetadataSection section; switch (property.Path.Section) { case PaintDotNet.Imaging.ExifSection.Image: section = MetadataSection.Image; break; case PaintDotNet.Imaging.ExifSection.Photo: section = MetadataSection.Exif; break; case PaintDotNet.Imaging.ExifSection.Interop: section = MetadataSection.Interop; break; case PaintDotNet.Imaging.ExifSection.GpsInfo: section = MetadataSection.Gps; break; default: throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Unexpected {0} type: {1}", nameof(PaintDotNet.Imaging.ExifSection), (int)property.Path.Section)); } MetadataKey metadataKey = new MetadataKey(section, property.Path.TagID); if (!items.ContainsKey(metadataKey)) { byte[] clonedData = PaintDotNet.Collections.EnumerableExtensions.ToArrayEx(property.Value.Data); items.Add(metadataKey, new MetadataEntry(metadataKey, (TagDataType)property.Value.Type, clonedData)); } } } #endif return(items); }
private long GetKeyId(MetadataKey key) { if (key == null) throw new ArgumentNullException("key"); string query = String.Format(@"SELECT `KeyId` FROM `Keys` WHERE `Name` = '{0}' AND `TypeId` = '{1}'", key.Name, (int)key.Type); var result = ExecuteScalar(query); if (result != null) keyIds[key] = (long)result; return result != null ? (long)result : 0; }
public IEnumerable<IObjectMetadata> Fetch(MetadataKey key) { string query = String.Format(@"SELECT * FROM `Metadata` INNER JOIN ObjectUrls ON `ObjectUrls`.`ObjectUrlId` = `Metadata`.`ObjectUrlId` INNER JOIN Keys ON `Keys`.`KeyId` = `Metadata`.`KeyId` WHERE `Keys`.`Name` = '{0}' AND `Keys`.`TypeId` = '{1}'", key.Name, (int)key.Type); return ParseResult(ExecuteReader(query)); }
public override void setMetadataStatus(MetadataKey metadataKey, MetadataStatus metadataStatus) { Log.v(TAG, "setMetadataStatus: " + metadataKey + ", " + metadataStatus); }
private static WebPNative.MetadataParams CreateWebPMetadata(Document doc) { byte[] iccProfileBytes = null; byte[] exifBytes = null; byte[] xmpBytes = null; string colorProfile = doc.Metadata.GetUserValue(WebPMetadataNames.ColorProfile); if (!string.IsNullOrEmpty(colorProfile)) { iccProfileBytes = Convert.FromBase64String(colorProfile); } string exif = doc.Metadata.GetUserValue(WebPMetadataNames.EXIF); if (!string.IsNullOrEmpty(exif)) { exifBytes = Convert.FromBase64String(exif); } string xmp = doc.Metadata.GetUserValue(WebPMetadataNames.XMP); if (!string.IsNullOrEmpty(xmp)) { xmpBytes = Convert.FromBase64String(xmp); } if (iccProfileBytes == null || exifBytes == null) { Dictionary <MetadataKey, MetadataEntry> propertyItems = GetMetadataFromDocument(doc); if (propertyItems != null) { ExifColorSpace exifColorSpace = ExifColorSpace.Srgb; if (iccProfileBytes != null) { exifColorSpace = ExifColorSpace.Uncalibrated; } else { MetadataKey iccProfileKey = MetadataKeys.Image.InterColorProfile; if (propertyItems.TryGetValue(iccProfileKey, out MetadataEntry iccProfileItem)) { iccProfileBytes = iccProfileItem.GetData(); propertyItems.Remove(iccProfileKey); exifColorSpace = ExifColorSpace.Uncalibrated; } } if (exifBytes == null) { exifBytes = new ExifWriter(doc, propertyItems, exifColorSpace).CreateExifBlob(); } } } #if !PDN_3_5_X if (xmpBytes == null) { PaintDotNet.Imaging.XmpPacket xmpPacket = doc.Metadata.TryGetXmpPacket(); if (xmpPacket != null) { string xmpPacketAsString = xmpPacket.ToString(); xmpBytes = System.Text.Encoding.UTF8.GetBytes(xmpPacketAsString); } } #endif if (iccProfileBytes != null || exifBytes != null || xmpBytes != null) { return(new WebPNative.MetadataParams(iccProfileBytes, exifBytes, xmpBytes)); } return(null); }