Deletes a tag from a file, if the file supports tags (TIFF or Exif).
public void DeleteTag(string fileName,int pageNumber,int id)
Public Overloads Sub DeleteTag( _ByVal fileName As String, _ByVal pageNumber As Integer, _ByVal id As Integer _)
- (BOOL)deleteTag:(NSUInteger)tagIdfromFile:(NSString *)filepageNumber:(NSInteger)pageNumbererror:(NSError **)error
public:void DeleteTag(String^ fileName,int pageNumber,int id)
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.
If you want to delete the tag from a particular IFD in the file, set RasterCodecs.Options.Tiff.Save.UseImageFileDirectoryOffset to true, and set RasterCodecs.Options.Tiff.Save.ImageFileDirectoryOffset to the IFD in question. This method will delete tags only from the main IFDs that make up an image. Some TIFF tags are themselves SubIFDs. You can delete tags from such SubIFDs by using RasterCodecs.Options.Tiff.Save.UseImageFileDirectoryOffset and RasterCodecs.Options.Tiff.Save.ImageFileDirectoryOffset specifying the IFD as above.
Notes:
When you add or remove tags, the tags array at the end of the file is re-written. When you modify existing tags, the new tag value is added to the file and the IFD is modified as necessary. In all of these cases, there is no image recompression.
This example will create a TIF file, add a certain tag to it then delete it
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;using LeadtoolsExamples.Common;public void TagExample(){RasterCodecs codecs = new RasterCodecs();string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_PageNumberTag.tif");// Convert the source file to TIFConsole.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 tagConsole.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 fileConsole.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 fileConsole.WriteLine("Deleting the tag from the file");codecs.DeleteTag(destFileName, 1, pageNumberTagId);// Make sure the tag is deletedConsole.WriteLine("Reading the tag from the file again");readTag = codecs.ReadTag(destFileName, 1, pageNumberTagId);if (readTag == null)Console.WriteLine("Tag was not found");elseConsole.WriteLine("Tag is found, this should not happen");Debug.Assert(readTag == null);// Clean upcodecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingImports Leadtools.SvgPublic Sub TagExample()Dim codecs As RasterCodecs = New RasterCodecs()Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_PageNumberTag.tif")' Convert the source file to TIFConsole.WriteLine("Converting the source file to TIF")codecs.Convert(srcFileName, destFileName, RasterImageFormat.Tif, 0, 0, 24, Nothing)Const pageNumberTagId As Integer = 297Dim pageNumber As Integer = 7Dim writeTag As RasterTagMetadata = New RasterTagMetadata()writeTag.Id = pageNumberTagIdwriteTag.DataType = RasterTagMetadataDataType.Int32writeTag.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 = 0Do While i < writeTagData.LengthConsole.Write("{0:X} ", writeTagData(i))i += 1LoopConsole.WriteLine()' Add the tagConsole.WriteLine("Writing the page number tag with data = {0} to the file", pageNumber)codecs.WriteTag(destFileName, 1, writeTag)' Read the tag and make sure it is in the fileConsole.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 = 0Do While i < readTagData.LengthConsole.Write("{0:X} ", readTagData(i))i += 1LoopConsole.WriteLine()Debug.Assert(writeTag.Id = readTag.Id)Debug.Assert(writeTag.DataType = readTag.DataType)Debug.Assert(writeTagData.Length = writeTagData.Length)i = 0Do While i < writeTagData.LengthDebug.Assert(writeTagData(i) = readTagData(i))i += 1Loop' Delete the tag from the fileConsole.WriteLine("Deleting the tag from the file")codecs.DeleteTag(destFileName, 1, pageNumberTagId)' Make sure the tag is deletedConsole.WriteLine("Reading the tag from the file again")readTag = codecs.ReadTag(destFileName, 1, pageNumberTagId)If readTag Is Nothing ThenConsole.WriteLine("Tag was not found")ElseConsole.WriteLine("Tag is found, this should not happen")End IfDebug.Assert(readTag Is Nothing)' Clean upcodecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
c#[Silverlight C# Example]using Leadtools;using Leadtools.Codecs;using Leadtools.Examples;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Windows.Media;public void TagExample(Stream inStreamCmp, Stream outStreamTif){RasterCodecs codecs = new RasterCodecs();// Convert the source file to TIFDebug.WriteLine("Converting the source file to TIF");codecs.Convert(inStreamCmp, outStreamTif, 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 });Debug.WriteLine("Writing the following tag to the file:");Debug.WriteLine(" ID: {0}", writeTag.Id);Debug.WriteLine(" DataType: {0}", writeTag.DataType);Debug.WriteLine(" Data: ");byte[] writeTagData = writeTag.GetData();for (int i = 0; i < writeTagData.Length; i++)Debug.WriteLine("{0:X} ", writeTagData[i]);Debug.WriteLine("");// Add the tagDebug.WriteLine("Writing the page number tag with data = {0} to the file", pageNumber);//FileStream fsDest = new FileStream(destFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);codecs.WriteTag(outStreamTif, 1, writeTag);// Read the tag and make sure its in the fileDebug.WriteLine("Reading the page number tag from the file");RasterTagMetadata readTag = codecs.ReadTag(outStreamTif, 1, pageNumberTagId);Debug.WriteLine("Tag read from the file:");Debug.WriteLine(" ID: {0}", readTag.Id);Debug.WriteLine(" DataType: {0}", readTag.DataType);Debug.WriteLine(" Data: ");byte[] readTagData = readTag.GetData();for (int i = 0; i < readTagData.Length; i++)Debug.WriteLine("{0:X} ", readTagData[i]);Debug.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 fileDebug.WriteLine("Deleting the tag from the file");codecs.DeleteTag(outStreamTif, 1, pageNumberTagId);// Make sure the tag is deletedDebug.WriteLine("Reading the tag from the file again");readTag = codecs.ReadTag(outStreamTif, 1, pageNumberTagId);if (readTag == null)Debug.WriteLine("Tag was not found");elseDebug.WriteLine("Tag is found, this should not happen");Debug.Assert(readTag == null);}vb[Silverlight VB Example]Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPublic Sub TagExample(ByVal inStreamCmp As Stream, ByVal outStreamTif As Stream)Dim codecs As RasterCodecs = New RasterCodecs()' Convert the source file to TIFDebug.WriteLine("Converting the source file to TIF")codecs.Convert(inStreamCmp, outStreamTif, RasterImageFormat.Tif, 0, 0, 24, Nothing)Const pageNumberTagId As Integer = 297Dim pageNumber As Integer = 7Dim writeTag As RasterTagMetadata = New RasterTagMetadata()writeTag.Id = pageNumberTagIdwriteTag.DataType = RasterTagMetadataDataType.Int32writeTag.FromInt32(New Integer() {pageNumber})Debug.WriteLine("Writing the following tag to the file:")Debug.WriteLine(" ID: {0}", writeTag.Id)Debug.WriteLine(" DataType: {0}", writeTag.DataType)Debug.WriteLine(" Data: ")Dim writeTagData As Byte() = writeTag.GetData()Dim i As Integer = 0Do While i < writeTagData.LengthDebug.WriteLine("{0:X} ", writeTagData(i))i += 1LoopDebug.WriteLine("")' Add the tagDebug.WriteLine("Writing the page number tag with data = {0} to the file", pageNumber)'FileStream fsDest = new FileStream(destFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);codecs.WriteTag(outStreamTif, 1, writeTag)' Read the tag and make sure its in the fileDebug.WriteLine("Reading the page number tag from the file")Dim readTag As RasterTagMetadata = codecs.ReadTag(outStreamTif, 1, pageNumberTagId)Debug.WriteLine("Tag read from the file:")Debug.WriteLine(" ID: {0}", readTag.Id)Debug.WriteLine(" DataType: {0}", readTag.DataType)Debug.WriteLine(" Data: ")Dim readTagData As Byte() = readTag.GetData()i = 0Do While i < readTagData.LengthDebug.WriteLine("{0:X} ", readTagData(i))i += 1LoopDebug.WriteLine("")Debug.Assert(writeTag.Id = readTag.Id)Debug.Assert(writeTag.DataType = readTag.DataType)Debug.Assert(writeTagData.Length = writeTagData.Length)i = 0Do While i < writeTagData.LengthDebug.Assert(writeTagData(i) = readTagData(i))i += 1Loop' Delete the tag from the fileDebug.WriteLine("Deleting the tag from the file")codecs.DeleteTag(outStreamTif, 1, pageNumberTagId)' Make sure the tag is deletedDebug.WriteLine("Reading the tag from the file again")readTag = codecs.ReadTag(outStreamTif, 1, pageNumberTagId)If readTag Is Nothing ThenDebug.WriteLine("Tag was not found")ElseDebug.WriteLine("Tag is found, this should not happen")End IfDebug.Assert(readTag Is Nothing)End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
