public void WriteTag(
Stream stream,
int pageNumber,
RasterTagMetadata tag
)
- (BOOL)writeTag:(nullable LTRasterTagMetadata *)tag
toStream:(LTLeadStream *)stream
pageNumber:(NSInteger)pageNumber
error:(NSError **)error
public void writeTag(ILeadStream stream, int pageNumber, RasterTagMetadata tag)
public:
void WriteTag(
Stream^ stream,
int pageNumber,
RasterTagMetadata^ tag
)
def WriteTag(self,stream,pageNumber,tag):
stream
A Stream that contains the file data.
pageNumber
1-based index of the page at which to write the tag.
tag
Tag to identify the data in the TIFF file.
This method writes tags into an existing file or changes tags in an existing file.
This method with TIFF and other files that support Exif metadata (JPEG, PNG).
Note Use this method carefully. LEADTOOLS will not restrict the tags that you write. If you write bad tags, the file might become corrupted. Consult the TIFF documentation for a list of predefined tags. It is recommended that you write only the user-defined tags (the tags between 0x8000 and 0xFFFF).
See the TIFF documentation for a complete list of the TIFF tags and types.
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.
Some restrictions apply to this function if you use an IFD to indicate to which page to write the tag. See the Loading and Saving Large TIFF / BigTIFF Files topic for more information.
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:\LEADTOOLS23\Resources\Images";
}
import java.io.*;
import java.net.*;
import java.nio.file.Paths;
import java.util.*;
import java.time.Instant;
import java.time.Duration;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.codecs.RasterCodecs.FeedCallbackThunk;
import leadtools.drawing.internal.*;
import leadtools.imageprocessing.*;
import leadtools.imageprocessing.color.ChangeIntensityCommand;
import leadtools.svg.*;
public void tagExample() throws IOException {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
RasterCodecs codecs = new RasterCodecs();
String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp");
String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1_CustomTag.tif");
// Convert the source file to TIF
System.out.println("Converting the source file to TIF");
codecs.convert(srcFileName, destFileName, RasterImageFormat.TIF, 0, 0, 24, null);
final int customTagId = 0x8000; // 32768 in decimal //
int customTagValue = 7;
RasterTagMetadata writeTag = new RasterTagMetadata();
writeTag.setId(customTagId);
writeTag.setDataType(RasterTagMetadataDataType.INT_32);
writeTag.fromInt32(new int[] { customTagValue });
System.out.println("Writing the following tag to the file:");
System.out.println(" ID: " + writeTag.getId());
System.out.println(" DataType: " + writeTag.getDataType());
System.out.println(" Data: ");
byte[] writeTagData = writeTag.getData();
for (int i = 0; i < writeTagData.length; i++)
System.out.println(writeTagData[i]);
System.out.println(" ");
// Add the tag
System.out.printf("Writing the custom tag with data = %s to the file%n", customTagValue);
ILeadStream destFileStream = LeadStreamFactory.create(destFileName);
codecs.writeTag(destFileStream, 1, writeTag);
// Read the tag and make sure its in the file
System.out.println("Reading the custom tag from the file");
RasterTagMetadata readTag = codecs.readTag(destFileStream, 1, customTagId);
System.out.println("Tag read from the file:");
System.out.println(" ID: " + readTag.getId());
System.out.println(" DataType: +" + readTag.getDataType());
System.out.println(" Data: ");
byte[] readTagData = readTag.getData();
for (int i = 0; i < readTagData.length; i++)
System.out.println(readTagData[i]);
System.out.println(" ");
assertTrue(writeTag.getId() == readTag.getId());
assertTrue(writeTag.getDataType() == readTag.getDataType());
assertTrue(writeTagData.length == writeTagData.length);
for (int i = 0; i < writeTagData.length; i++)
assertTrue(writeTagData[i] == readTagData[i]);
// Delete the tag from the file
System.out.println("Deleting the tag from the file");
codecs.deleteTag(destFileStream, 1, customTagId);
// Make sure the tag is deleted
System.out.println("Reading the tag from the file again");
readTag = codecs.readTag(destFileStream, 1, customTagId);
if (readTag == null)
System.out.println("Tag was not found");
else
System.out.println("Tag is found, this should not happen");
assertTrue(readTag == null);
// Clean up
destFileStream.close();
codecs.dispose();
}
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