←Select platform

DeleteTag(Stream,int,int) Method

Summary
Deletes a tag from a stream, if the file supports tags (TIFF, Exif, PNG).
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void DeleteTag( 
   Stream stream, 
   int pageNumber, 
   int id 
) 
- (BOOL)deleteTag:(NSUInteger)tagId  
       fromStream:(LTLeadStream *)stream  
       pageNumber:(NSInteger)pageNumber  
            error:(NSError **)error 
public void deleteTag(ILeadStream stream, int pageNumber, int id) 
public: 
void DeleteTag(  
   Stream^ stream, 
   int pageNumber, 
   int id 
)  
def DeleteTag(self,stream,pageNumber,id): 

Parameters

stream
A Stream containing the image data 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.

Remarks

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:

  • The Leadtools.Codecs.Cmp.dll codec is used to delete the tag from all the TIFF and Exif files.
  • Do not attempt to use this method to delete tags from inside the TagFound event. If you want to delete tags that you enumerate, use the TagFound event to add the tags to a list. Upon returning from EnumTags, you can delete all the tags from the list.
  • You should be careful when you delete non-custom tags (tags below 32768). If you delete the wrong tag, you might corrupt the TIF file!.

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.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
 
public void TagExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_CustomTag.tif"); 
 
   // Convert the source file to TIF 
   Debug.WriteLine("Converting the source file to TIF"); 
   codecs.Convert(srcFileName, destFileName, RasterImageFormat.Tif, 0, 0, 24, null); 
 
   const int customTagId = 0x8000; /* 32768 in decimal */ 
   int customTagValue = 7; 
 
   RasterTagMetadata writeTag = new RasterTagMetadata(); 
   writeTag.Id = customTagId; 
   writeTag.DataType = RasterTagMetadataDataType.Int32; 
   writeTag.FromInt32(new int[] { customTagValue }); 
 
   Debug.WriteLine("Writing the following tag to the file:"); 
   Debug.WriteLine("  ID: {0}", writeTag.Id); 
   Debug.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]); 
   Debug.WriteLine(" "); 
 
   // Add the tag 
   Debug.WriteLine("Writing the custom tag with data = {0} to the file", customTagValue); 
   codecs.WriteTag(destFileName, 1, writeTag); 
 
   // Read the tag and make sure its in the file 
   Debug.WriteLine("Reading the custom tag from the file"); 
   RasterTagMetadata readTag = codecs.ReadTag(destFileName, 1, customTagId); 
 
   Debug.WriteLine("Tag read from the file:"); 
   Debug.WriteLine("  ID: {0}", readTag.Id); 
   Debug.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]); 
   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 file 
   Debug.WriteLine("Deleting the tag from the file"); 
   codecs.DeleteTag(destFileName, 1, customTagId); 
 
   // Make sure the tag is deleted 
   Debug.WriteLine("Reading the tag from the file again"); 
   readTag = codecs.ReadTag(destFileName, 1, customTagId); 
 
   if (readTag == null) 
      Debug.WriteLine("Tag was not found"); 
   else 
      Debug.WriteLine("Tag is found, this should not happen"); 
 
   Debug.Assert(readTag == null); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.