[SerializableAttribute()]
public class RasterMarkerMetadata : RasterMetadata
@interface LTRasterMarkerMetadata : LTRasterMetadata
public class RasterMarkerMetadata
extends RasterMetadata
implements java.io.Serializable
[SerializableAttribute()]
public ref class RasterMarkerMetadata : public RasterMetadata
class RasterMarkerMetadata(RasterMetadata):
JPEG files contain metadata information in user-defined markers.
The user-defined markers are in the range 0xE0 to 0xFE. These markers can have a maximum size of 0xFFFD, or 65533 bytes.
The markers below 0xE0 are reserved for the encoding of the image and inserting a reserved marker can make a file invalid. Therefore, you should not use reserved markers unless you are well acquainted with markers and image encoding in JPEG files.
TIFF files do not contain markers, however, LEADTOOLS provides a "workaround" for transferring Exif comments from JPEG files to TIFF files, and vice versa. The Exif metadata information from a TIFF file will be loaded as an APP1 marker. Therefore, you can load Exif metadata from an uncompressed file and store it in a compressed Exif file.
You can also take metadata information from a compressed Exif file and store it in an uncompressed Exif file. Please note however, that some information cannot be stored inside uncompressed Exif files. For example, audio data is stored in APP2 markers and there is no built-in support for saving APP2 markers in TIFF files. However, you can still save the audio data yourself, using a custom tag.
This example will write different markers to an existing TIF file then read them as a test.
using Leadtools;
using Leadtools.Codecs;
public void RasterMarkerMetadataExample()
{
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_markers.tif");
// Load the image
RasterImage image = codecs.Load(srcFileName);
codecs.Save(image, destFileName, RasterImageFormat.ExifJpeg, 24);
image.Dispose();
// write a marker to the file
RasterMarkerMetadata markerWrite = new RasterMarkerMetadata();
byte[] data = new byte[100];
for (int i = 0; i < data.Length; i++)
data[i] = (byte)(i + 1);
markerWrite.Id = RasterMarkerMetadata.App2;
markerWrite.SetData(data);
Console.WriteLine("Writing the marker");
codecs.WriteMarker(destFileName, 1, markerWrite);
// read the markers from the file and check for ours
IList<RasterMarkerMetadata> markers = codecs.ReadMarkers(destFileName);
RasterMarkerMetadata markerRead = null;
for (int i = 0; i < markers.Count && markerRead == null; i++)
{
if (markers[i].Id == markerWrite.Id)
markerRead = markers[i];
}
Assert.IsTrue(markerRead.Id == markerWrite.Id);
byte[] dataRead = markerRead.GetData();
byte[] dataWrite = markerWrite.GetData();
Assert.IsTrue(dataRead.Length == dataWrite.Length);
for (int i = 0; i < dataRead.Length; i++)
Assert.IsTrue(dataRead[i] == dataWrite[i]);
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
import java.io.File;
import java.io.IOException;
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.*;
public void rasterMarkerMetadataExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
RasterCodecs codecs = new RasterCodecs();
codecs.setThrowExceptionsOnInvalidImages(true);
String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp");
String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1_markers.tif");
ILeadStream leadStream = LeadStreamFactory.create(destFileName);
// Load the image
RasterImage image = codecs.load(srcFileName);
codecs.save(image, destFileName, RasterImageFormat.EXIF_JPEG, 24);
image.dispose();
// write a marker to the file
RasterMarkerMetadata markerWrite = new RasterMarkerMetadata();
byte[] data = new byte[100];
for (int i = 0; i < data.length; i++)
data[i] = (byte) (i + 1);
markerWrite.setId(RasterMarkerMetadata.APP2);
markerWrite.setData(data);
System.out.println("Writing the marker");
codecs.writeMarker(leadStream, 1, markerWrite);
// read the markers from the file and check for ours
RasterCollection<RasterMarkerMetadata> markers = codecs.readMarkers(leadStream);
RasterMarkerMetadata markerRead = null;
for (int i = 0; i < markers.size() && markerRead == null; i++) {
if (markers.get(i).getId() == markerWrite.getId())
markerRead = markers.get(i);
}
assertTrue(markerRead.getId() == markerWrite.getId());
byte[] dataRead = markerRead.getData();
byte[] dataWrite = markerWrite.getData();
assertTrue(dataRead.length == dataWrite.length);
for (int i = 0; i < dataRead.length; i++) {
assertTrue(dataRead[i] == dataWrite[i]);
}
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