Deletes a tag from a file, if the file supports tags (TIFF or Exif).
Syntax
Visual Basic (Usage) | Copy Code |
---|
Dim instance As RasterCodecs
Dim fileName As String
Dim pageNumber As Integer
Dim id As Integer
instance.DeleteTag(fileName, pageNumber, id)
|
Parameters
- fileName
- A String containing the name of the file from which to delete the tag.
- pageNumber
- The 1-based index of the page from which the tag will be deleted. Use -1 to delete the tag from
the last page. Use 1 to delete the tag from the first page.
- id
- The ID of the tag in the TIFF file. The tag IDs are between 0 and 65535.
Example
This example will create a TIF file, add a certain tag to it then delete it
Visual Basic | Copy Code |
---|
Public Sub TagExample()
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_PageNumberTag.tif"
Console.WriteLine("Converting the source file to TIF")
codecs.Convert(srcFileName, destFileName, RasterImageFormat.Tif, 0, 0, 24, Nothing)
Const pageNumberTagId As Integer = 297
Dim pageNumber As Integer = 7
Dim writeTag As RasterTagMetadata = New RasterTagMetadata()
writeTag.Id = pageNumberTagId
writeTag.DataType = RasterTagMetadataDataType.Int32
writeTag.FromInt32(New Integer() {pageNumber})
Console.WriteLine("Writing the following tag to the file:")
Console.WriteLine(" ID: {0}", writeTag.Id)
Console.WriteLine(" DataType: {0}", writeTag.DataType)
Console.Write(" Data: ")
Dim writeTagData As Byte() = writeTag.GetData()
Dim i As Integer = 0
Do While i < writeTagData.Length
Console.Write("{0:X} ", writeTagData(i))
i += 1
Loop
Console.WriteLine()
Console.WriteLine("Writing the page number tag with data = {0} to the file", pageNumber)
codecs.WriteTag(destFileName, 1, writeTag)
Console.WriteLine("Reading the page number tag from the file")
Dim readTag As RasterTagMetadata = codecs.ReadTag(destFileName, 1, pageNumberTagId)
Console.WriteLine("Tag read from the file:")
Console.WriteLine(" ID: {0}", readTag.Id)
Console.WriteLine(" DataType: {0}", readTag.DataType)
Console.Write(" Data: ")
Dim readTagData As Byte() = readTag.GetData()
i = 0
Do While i < readTagData.Length
Console.Write("{0:X} ", readTagData(i))
i += 1
Loop
Console.WriteLine()
Debug.Assert(writeTag.Id = readTag.Id)
Debug.Assert(writeTag.DataType = readTag.DataType)
Debug.Assert(writeTagData.Length = writeTagData.Length)
i = 0
Do While i < writeTagData.Length
Debug.Assert(writeTagData(i) = readTagData(i))
i += 1
Loop
Console.WriteLine("Deleting the tag from the file")
codecs.DeleteTag(destFileName, 1, pageNumberTagId)
Console.WriteLine("Reading the tag from the file again")
readTag = codecs.ReadTag(destFileName, 1, pageNumberTagId)
If readTag Is Nothing Then
Console.WriteLine("Tag was not found")
Else
Console.WriteLine("Tag is found, this should not happen")
End If
Debug.Assert(readTag Is Nothing)
codecs.Dispose()
RasterCodecs.Shutdown()
End Sub |
C# | Copy Code |
---|
public void TagExample() { RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_PageNumberTag.tif"; // Convert the source file to TIF Console.WriteLine("Converting the source file to TIF"); codecs.Convert(srcFileName, destFileName, RasterImageFormat.Tif, 0, 0, 24, null); const int pageNumberTagId = 297; int pageNumber = 7; RasterTagMetadata writeTag = new RasterTagMetadata(); writeTag.Id = pageNumberTagId; writeTag.DataType = RasterTagMetadataDataType.Int32; writeTag.FromInt32(new int[] { pageNumber }); Console.WriteLine("Writing the following tag to the file:"); Console.WriteLine(" ID: {0}", writeTag.Id); Console.WriteLine(" DataType: {0}", writeTag.DataType); Console.Write(" Data: "); byte[] writeTagData = writeTag.GetData(); for(int i = 0; i < writeTagData.Length; i++) Console.Write("{0:X} ", writeTagData[i]); Console.WriteLine(); // Add the tag Console.WriteLine("Writing the page number tag with data = {0} to the file", pageNumber); codecs.WriteTag(destFileName, 1, writeTag); // Read the tag and make sure its in the file Console.WriteLine("Reading the page number tag from the file"); RasterTagMetadata readTag = codecs.ReadTag(destFileName, 1, pageNumberTagId); Console.WriteLine("Tag read from the file:"); Console.WriteLine(" ID: {0}", readTag.Id); Console.WriteLine(" DataType: {0}", readTag.DataType); Console.Write(" Data: "); byte[] readTagData = readTag.GetData(); for(int i = 0; i < readTagData.Length; i++) Console.Write("{0:X} ", readTagData[i]); Console.WriteLine(); Debug.Assert(writeTag.Id == readTag.Id); Debug.Assert(writeTag.DataType == readTag.DataType); Debug.Assert(writeTagData.Length == writeTagData.Length); for(int i = 0; i < writeTagData.Length; i++) Debug.Assert(writeTagData[i] == readTagData[i]); // Delete the tag from the file Console.WriteLine("Deleting the tag from the file"); codecs.DeleteTag(destFileName, 1, pageNumberTagId); // Make sure the tag is deleted Console.WriteLine("Reading the tag from the file again"); readTag = codecs.ReadTag(destFileName, 1, pageNumberTagId); if(readTag == null) Console.WriteLine("Tag was not found"); else Console.WriteLine("Tag is found, this should not happen"); Debug.Assert(readTag == null); // Clean up codecs.Dispose(); RasterCodecs.Shutdown(); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also