Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.8.30
|
Leadtools.Codecs Namespace > RasterCodecs Class > DeleteTag Method : DeleteTag(String,Int32,Int32) Method |
'Declaration
Public Overloads Sub DeleteTag( _ ByVal fileName As String, _ ByVal pageNumber As Integer, _ ByVal id As Integer _ )
'Usage
Dim instance As RasterCodecs Dim fileName As String Dim pageNumber As Integer Dim id As Integer instance.DeleteTag(fileName, pageNumber, id)
- (BOOL)deleteTag:(NSUInteger)tagId fromFile:(NSString *)file pageNumber:(NSInteger)pageNumber error:(NSError **)error
function Leadtools.Codecs.RasterCodecs.DeleteTag(String,Int32,Int32)( fileName , pageNumber , id )
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
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Drawing Imports Leadtools.Svg Public 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 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() ' 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 it is in the file 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 ' 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 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) ' Clean up codecs.Dispose() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
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_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(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
RasterCodecsExamples.prototype.TagExample = function () { Tools.SetLicense(); with (Leadtools) { with (Leadtools.Codecs) { var codecs = new RasterCodecs(); var srcFileName = "Assets\\Image1.cmp"; var destFileName = "Image1_PageNumberTag.tif"; var loadFile; var saveFile; var writeTag = new RasterTagMetadata(); var writeTagData; var pageNumberTagId = 297; var pageNumber = 7; // Convert the source file to TIF return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFileX) { loadFile = loadFileX; return Tools.AppLocalFolder().createFileAsync(destFileName) }) .then(function (saveFileX) { saveFile = saveFileX; console.info("Converting the source file to TIF"); return codecs.convertAsync(LeadStreamFactory.create(loadFile), LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 0, 0, 24, null) }) .then(function () { writeTag.id = pageNumberTagId; writeTag.dataType = RasterTagMetadataDataType.int32; writeTag.fromInt32([pageNumber]); console.info("Writing the following tag to the file:"); console.info(" ID: ", writeTag.Id); console.info(" DataType: ", writeTag.DataType); console.info(" Data: "); writeTagData = writeTag.getData(); for (var i = 0; i < writeTagData.length; i++) console.info(writeTagData[i]); console.info(""); // Add the tag console.info("Writing the page number tag with data = ", pageNumber, " to the file"); return codecs.writeTagAsync(LeadStreamFactory.create(saveFile), 1, writeTag) }) .then(function () { // Read the tag and make sure its in the file console.info("Reading the page number tag from the file"); return codecs.readTagAsync(LeadStreamFactory.create(saveFile), 1, pageNumberTagId) }) .then(function (readTag) { console.info("Tag read from the file:"); console.info(" ID: ", readTag.id); console.info(" DataType: ", readTag.dataType); console.info(" Data: "); var readTagData = readTag.getData(); for (var i = 0; i < readTagData.length; i++) console.info(readTagData[i]); console.info(""); console.assert(writeTag.id == readTag.id, "writeTag.Id == readTag.id"); console.assert(writeTag.dataType == readTag.dataType, "writeTag.dataType == readTag.dataType"); console.assert(writeTagData.length == writeTagData.length, "writeTagData.length == writeTagData.length"); for (var i = 0; i < writeTagData.length; i++) console.assert(writeTagData[i] == readTagData[i], "writeTagData[i] == readTagData[i]"); // Delete the tag from the file console.info("Deleting the tag from the file"); return codecs.deleteTagAsync(LeadStreamFactory.create(saveFile), 1, pageNumberTagId) }) .then(function () { // Make sure the tag is deleted console.info("Reading the tag from the file again"); return codecs.readTagAsync(LeadStreamFactory.create(saveFile), 1, pageNumberTagId) }) .then(function (readTag) { if (readTag == null) console.info("Tag was not found"); else console.info("Tag is found, this should not happen"); console.assert(readTag == null, "readTag == null"); // Clean up codecs.close(); }); } } }
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; public async Task TagExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = @"Assets\Image1.cmp"; string destFileName = "Image1_PageNumberTag.tif"; // Convert the source file to TIF StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName); Debug.WriteLine("Converting the source file to TIF"); await codecs.ConvertAsync(LeadStreamFactory.Create(loadFile), LeadStreamFactory.Create(saveFile), 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 tag Debug.WriteLine("Writing the page number tag with data = {0} to the file", pageNumber); await codecs.WriteTagAsync(LeadStreamFactory.Create(saveFile), 1, writeTag); // Read the tag and make sure its in the file Debug.WriteLine("Reading the page number tag from the file"); RasterTagMetadata readTag = await codecs.ReadTagAsync(LeadStreamFactory.Create(saveFile), 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(""); Assert.IsTrue(writeTag.Id == readTag.Id); Assert.IsTrue(writeTag.DataType == readTag.DataType); Assert.IsTrue(writeTagData.Length == writeTagData.Length); for (int i = 0; i < writeTagData.Length; i++) Assert.IsTrue(writeTagData[i] == readTagData[i]); // Delete the tag from the file Debug.WriteLine("Deleting the tag from the file"); await codecs.DeleteTagAsync(LeadStreamFactory.Create(saveFile), 1, pageNumberTagId); // Make sure the tag is deleted Debug.WriteLine("Reading the tag from the file again"); readTag = await codecs.ReadTagAsync(LeadStreamFactory.Create(saveFile), 1, pageNumberTagId); if (readTag == null) Debug.WriteLine("Tag was not found"); else Debug.WriteLine("Tag is found, this should not happen"); Assert.IsTrue(readTag == null); // Clean up codecs.Dispose(); }
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 TIF Debug.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 tag Debug.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 file Debug.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 file Debug.WriteLine("Deleting the tag from the file"); codecs.DeleteTag(outStreamTif, 1, pageNumberTagId); // Make sure the tag is deleted Debug.WriteLine("Reading the tag from the file again"); readTag = codecs.ReadTag(outStreamTif, 1, pageNumberTagId); if(readTag == null) Debug.WriteLine("Tag was not found"); else Debug.WriteLine("Tag is found, this should not happen"); Debug.Assert(readTag == null); }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Windows.Media Public Sub TagExample(ByVal inStreamCmp As Stream, ByVal outStreamTif As Stream) Dim codecs As RasterCodecs = New RasterCodecs() ' Convert the source file to TIF Debug.WriteLine("Converting the source file to TIF") codecs.Convert(inStreamCmp, outStreamTif, 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 }) 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 = 0 Do While i < writeTagData.Length Debug.WriteLine("{0:X} ", writeTagData(i)) i += 1 Loop Debug.WriteLine("") ' Add the tag Debug.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 file Debug.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 = 0 Do While i < readTagData.Length Debug.WriteLine("{0:X} ", readTagData(i)) i += 1 Loop Debug.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 ' Delete the tag from the file Debug.WriteLine("Deleting the tag from the file") codecs.DeleteTag(outStreamTif, 1, pageNumberTagId) ' Make sure the tag is deleted Debug.WriteLine("Reading the tag from the file again") readTag = codecs.ReadTag(outStreamTif, 1, pageNumberTagId) If readTag Is Nothing Then Debug.WriteLine("Tag was not found") Else Debug.WriteLine("Tag is found, this should not happen") End If Debug.Assert(readTag Is Nothing) End Sub