@@ -20,22 +20,35 @@ public static partial class MetadataExtensions
2020 public static JpegMetadata GetJpegMetadata ( this ImageMetadata metadata ) => metadata . GetFormatMetadata ( JpegFormat . Instance ) ;
2121
2222 /// <summary>
23- /// Saves the comment into <see cref="JpegMetadata"/>
23+ /// Sets the comment in <see cref="JpegMetadata"/>
2424 /// </summary>
2525 /// <param name="metadata">The metadata this method extends.</param>
26+ /// <param name="index">The index of comment to be inserted to.</param>
2627 /// <param name="comment">The comment string.</param>
27- public static void SaveComment ( this JpegMetadata metadata , string comment )
28+ public static void SetComment ( this JpegMetadata metadata , int index , string comment )
2829 {
29- ASCIIEncoding encoding = new ( ) ;
30+ if ( metadata . Comments == null )
31+ {
32+ return ;
33+ }
3034
35+ ASCIIEncoding encoding = new ( ) ;
3136 byte [ ] bytes = encoding . GetBytes ( comment ) ;
32- metadata . Comments ? . Add ( encoding . GetChars ( bytes ) ) ;
37+ List < Memory < char > > ? comments = metadata . Comments as List < Memory < char > > ;
38+ comments ? . Insert ( index , encoding . GetChars ( bytes ) ) ;
3339 }
3440
3541 /// <summary>
3642 /// Gets the comments from <see cref="JpegMetadata"/>
3743 /// </summary>
3844 /// <param name="metadata">The metadata this method extends.</param>
45+ /// <param name="index">The index of comment.</param>
3946 /// <returns>The IEnumerable string of comments.</returns>
40- public static IEnumerable < string > ? GetComments ( this JpegMetadata metadata ) => metadata . Comments ? . Select ( x => x . ToString ( ) ) ;
47+ public static string ? GetComment ( this JpegMetadata metadata , int index ) => metadata . Comments ? . ElementAtOrDefault ( index ) . ToString ( ) ;
48+
49+ /// <summary>
50+ /// Clears comments
51+ /// </summary>
52+ /// <param name="metadata">The <see cref="JpegMetadata"/>.</param>
53+ public static void ClearComments ( this JpegMetadata metadata ) => metadata . Comments ? . Clear ( ) ;
4154}
0 commit comments