|
|
|
@ -20,22 +20,35 @@ public static partial class MetadataExtensions |
|
|
|
public static JpegMetadata GetJpegMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(JpegFormat.Instance); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Saves the comment into <see cref="JpegMetadata"/>
|
|
|
|
/// Sets the comment in <see cref="JpegMetadata"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="metadata">The metadata this method extends.</param>
|
|
|
|
/// <param name="index">The index of comment to be inserted to.</param>
|
|
|
|
/// <param name="comment">The comment string.</param>
|
|
|
|
public static void SaveComment(this JpegMetadata metadata, string comment) |
|
|
|
public static void SetComment(this JpegMetadata metadata, int index, string comment) |
|
|
|
{ |
|
|
|
ASCIIEncoding encoding = new(); |
|
|
|
if (metadata.Comments == null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
ASCIIEncoding encoding = new(); |
|
|
|
byte[] bytes = encoding.GetBytes(comment); |
|
|
|
metadata.Comments?.Add(encoding.GetChars(bytes)); |
|
|
|
List<Memory<char>>? comments = metadata.Comments as List<Memory<char>>; |
|
|
|
comments?.Insert(index, encoding.GetChars(bytes)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the comments from <see cref="JpegMetadata"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="metadata">The metadata this method extends.</param>
|
|
|
|
/// <param name="index">The index of comment.</param>
|
|
|
|
/// <returns>The IEnumerable string of comments.</returns>
|
|
|
|
public static IEnumerable<string>? GetComments(this JpegMetadata metadata) => metadata.Comments?.Select(x => x.ToString()); |
|
|
|
public static string? GetComment(this JpegMetadata metadata, int index) => metadata.Comments?.ElementAtOrDefault(index).ToString(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clears comments
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="metadata">The <see cref="JpegMetadata"/>.</param>
|
|
|
|
public static void ClearComments(this JpegMetadata metadata) => metadata.Comments?.Clear(); |
|
|
|
} |
|
|
|
|