The Exif file format supports more complex comments than other formats. For a list of the comments, refer to Exif File Comments.
This example demonstrates how to handle Exif comments that are not stored as strings. (For a simpler example for saving strings, refer to the WriteComment method.)
This example does the following:
1. |
Loads an image. |
2. |
Updates the comment array by loading comments from the existing file. |
3. |
Reverses the image and creates a RasterCommentMetadataType.UserComment comment that says that the image has been reversed. |
4. |
Saves the file. (All of the comments are saved, including the one that we updated.) |
5. |
Reads and displays two of the comments from the saved file. One of them is the comment that we created. The other is comment that uses the Exif RasterTagMetadataDataType.URational data type. |
6. |
Clean up the comment array. |
VB
Private Sub WriteCommentsTest()
Dim codecs As New RasterCodecs()
Dim srcFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Image1.cmp"
Dim destFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Exif.tif"
Dim tempImage As RasterImage = codecs.Load(srcFileName)
' Flip the image.
Dim flipCmd As New FlipCommand(True)
flipCmd.Run(tempImage)
' Add a user comment to the file and save it in another name.
Dim comment As New RasterCommentMetadata()
comment.Type = RasterCommentMetadataType.UserComment
Dim comments As String = "The image has been flipped"
Dim data() As Char = comments.ToCharArray(0, comments.Length)
Dim dataComments(8 + comments.Length - 1) As Byte
' when you need to write a user comment the first 8 bytes
' must contain the "Ascii" word.
dataComments(0) = 41
dataComments(1) = 53
dataComments(2) = 43
dataComments(3) = 49
dataComments(4) = 49
dataComments(5) = 0
dataComments(6) = 0
dataComments(7) = 0
For i As Integer = 0 To comments.Length - 1
dataComments(8 + i) = CType(AscW(data(i)), Byte)
Next
' set the data property in the comment object to the dataComments array.
comment.FromByte(dataComments)
' add the user comment to the comments collection of the image
tempImage.Comments.Add(comment)
codecs.Options.Save.Comments = True
codecs.Save(tempImage, destFileName, RasterImageFormat.Exif, 24)
tempImage.Dispose()
' read the user comments and display it
comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.UserComment)
dataComments = comment.GetData()
Dim msg As String = "User comments = "
For i As Integer = 0 To dataComments.Length - 7
msg = msg + dataComments(i + 8).ToString
Next
MessageBox.Show(msg, "Notice")
End Sub
C#
private void WriteCommentsTest()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Image1.cmp";
string destFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Exif.tif";
RasterImage tempImage = codecs.Load(srcFileName);
// Flip the image.
FlipCommand flipCmd = new FlipCommand(true);
flipCmd.Run(tempImage);
// Add a user comment to the file and save it in another name.
RasterCommentMetadata comment = new RasterCommentMetadata();
comment.Type = RasterCommentMetadataType.UserComment;
string comments = "The image has been flipped";
char[] data = comments.ToCharArray(0, comments.Length);
byte[] dataComments = new byte[8 + comments.Length];
// when you need to write a user comment the first 8 bytes
// must contain the "Ascii" word.
dataComments[0] = 41;
dataComments[1] = 53;
dataComments[2] = 43;
dataComments[3] = 49;
dataComments[4] = 49;
dataComments[5] = 0;
dataComments[6] = 0;
dataComments[7] = 0;
for(int i = 0; i < comments.Length; i++)
dataComments[8 + i] = (byte)data[i];
// set the data property in the comment object to the dataComments array.
comment.FromByte(dataComments);
// add the user comment to the comments collection of the image
tempImage.Comments.Add(comment);
codecs.Options.Save.Comments = true;
codecs.Save(tempImage, destFileName, RasterImageFormat.Exif, 24);
tempImage.Dispose();
// read the user comments and display it
comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.UserComment);
dataComments = comment.GetData();
string msg = "User comments = ";
for(int i = 0; i < (dataComments.Length - 8); i++)
msg += (char)dataComments[i + 8];
MessageBox.Show(msg, "Notice");
}
Products |
Support |
Feedback: Implementing Exif Features |
Introduction |
Help Version 19.0.2017.6.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.