Imports Leadtools
Imports Leadtools.Codecs
Public Sub RasterMarkerMetadataExample()
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.ThrowExceptionsOnInvalidImages = True
Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_markers.tif")
' Load the image
Dim image As RasterImage = codecs.Load(srcFileName)
codecs.Save(image, destFileName, RasterImageFormat.ExifJpeg, 24)
image.Dispose()
' write a marker to the file
Dim markerWrite As RasterMarkerMetadata = New RasterMarkerMetadata()
Dim data As Byte() = New Byte(99) {}
Dim i As Integer = 0
Do While i < data.Length
data(i) = CByte(i + 1)
i += 1
Loop
markerWrite.Id = &HE0
markerWrite.SetData(data)
Console.WriteLine("Writing the marker")
codecs.WriteMarker(destFileName, 1, markerWrite)
' read the markers from the file and check for ours
Dim markers As RasterCollection(Of RasterMarkerMetadata) = codecs.ReadMarkers(destFileName)
Dim markerRead As RasterMarkerMetadata = Nothing
i = 0
Do While i < markers.Count AndAlso markerRead Is Nothing
If markers(i).Id = markerWrite.Id Then
markerRead = markers(i)
End If
i += 1
Loop
Debug.Assert(markerRead.Id = markerWrite.Id)
Dim dataRead As Byte() = markerRead.GetData()
Dim dataWrite As Byte() = markerWrite.GetData()
Debug.Assert(dataRead.Length = dataWrite.Length)
i = 0
Do While i < dataRead.Length
Debug.Assert(dataRead(i) = dataWrite(i))
i += 1
Loop
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;
public void RasterMarkerMetadataExample()
{
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
string srcFileName = Path.Combine(ImagesPath.Path,"Image1.cmp");
string destFileName = Path.Combine(ImagesPath.Path, "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 = 0xE0;
markerWrite.SetData(data);
Console.WriteLine("Writing the marker");
codecs.WriteMarker(destFileName, 1, markerWrite);
// read the markers from the file and check for ours
RasterCollection<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();
}
RasterMarkerMetadataExamples.prototype.RasterMarkerMetadataExample = function ( )
{
Tools.SetLicense ( ) ;
with ( Leadtools ) { with ( Leadtools.Codecs ) {
var codecs = new RasterCodecs();
codecs.throwExceptionsOnInvalidImages = true;
var srcFileName = "Assets\\Image1.cmp";
var destFileName = "Image1_markers.tif";
var image;
var saveFile;
var markerWrite = new RasterMarkerMetadata();
// Load the image
return Tools.AppInstallFolder().getFileAsync(srcFileName).then ( function ( loadFile ) {
return codecs.loadAsync(LeadStreamFactory.create(loadFile))})
.then ( function ( img ) {
image = img;
//Save the file as exif
return Tools.AppLocalFolder().createFileAsync(destFileName)})
.then(function (sfile) {
saveFile = sfile;
return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.exifJpeg, 24)})
.then ( function ( ) {
image.close();
// write a marker to the file
var data = new Array(100);
for(var i=0; i < data.length; i++ )
data[i] = (i + 1);
markerWrite.id = 0xE0;
markerWrite.setData(data);
console.info("Writing the marker");
return codecs.writeMarkerAsync(LeadStreamFactory.create(saveFile), 1, markerWrite)})
.then ( function ( ) {
// read the markers from the file and check for ours
return codecs.readMarkersAsync(LeadStreamFactory.create(saveFile))})
.then ( function ( markers ) {
var markerRead = null;
for(var i = 0; i < markers.size && markerRead == null; i++)
{
if(markers[i].id == markerWrite.id)
markerRead = markers[i];
}
console.assert(markerRead.id == markerWrite.id, "markerRead.id == markerWrite.id");
var dataRead = markerRead.getData();
var dataWrite = markerWrite.getData();
console.assert(dataRead.length == dataWrite.length, "dataRead.length == dataWrite.length");
for(var i = 0; i < dataRead.length; i++)
console.assert (dataRead[i] == dataWrite[i], "dataRead[i] == dataWrite[i]");
});
}
}
}
using Leadtools;
using Leadtools.Codecs;
public async Task RasterMarkerMetadataExample()
{
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
string srcFileName = @"Assets\Image1.cmp";
string destFileName = @"Image1_markers.tif";
// Load the image
StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
//Save the file as exif
StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), 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 = 0xE0;
markerWrite.SetData(data);
Debug.WriteLine("Writing the marker");
await codecs.WriteMarkerAsync(LeadStreamFactory.Create(saveFile), 1, markerWrite);
// read the markers from the file and check for ours
IList<RasterMarkerMetadata> markers = await codecs.ReadMarkersAsync(LeadStreamFactory.Create(saveFile));
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]);
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;
public void RasterMarkerMetadataExample(RasterImage image, Stream destStream)
{
RasterCodecs codecs = new RasterCodecs();
codecs.Save(image, destStream, 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 = 0xE0;
markerWrite.SetData(data);
Console.WriteLine("Writing the marker");
codecs.WriteMarker(destStream, 1, markerWrite);
// read the markers from the file and check for ours
RasterCollection<RasterMarkerMetadata> markers = codecs.ReadMarkers(destStream);
RasterMarkerMetadata markerRead = null;
for(int i = 0; i < markers.Count && markerRead == null; i++)
{
if(markers[i].Id == markerWrite.Id)
markerRead = markers[i];
}
Debug.Assert(markerRead.Id == markerWrite.Id);
byte[] dataRead = markerRead.GetData();
byte[] dataWrite = markerWrite.GetData();
Debug.Assert(dataRead.Length == dataWrite.Length);
for(int i = 0; i < dataRead.Length; i++)
Debug.Assert(dataRead[i] == dataWrite[i]);
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Public Sub RasterMarkerMetadataExample(ByVal image As RasterImage, ByVal destStream As Stream)
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, destStream, RasterImageFormat.ExifJpeg, 24)
image.Dispose()
' write a marker to the file
Dim markerWrite As RasterMarkerMetadata = New RasterMarkerMetadata()
Dim data As Byte() = New Byte(99){}
Dim i As Integer=0
Do While i < data.Length
data(i) = CByte(i + 1)
i += 1
Loop
markerWrite.Id = &HE0
markerWrite.SetData(data)
Console.WriteLine("Writing the marker")
codecs.WriteMarker(destStream, 1, markerWrite)
' read the markers from the file and check for ours
Dim markers As RasterCollection(Of RasterMarkerMetadata) = codecs.ReadMarkers(destStream)
Dim markerRead As RasterMarkerMetadata = Nothing
i = 0
Do While i < markers.Count AndAlso markerRead Is Nothing
If markers(i).Id = markerWrite.Id Then
markerRead = markers(i)
End If
i += 1
Loop
Debug.Assert(markerRead.Id = markerWrite.Id)
Dim dataRead As Byte() = markerRead.GetData()
Dim dataWrite As Byte() = markerWrite.GetData()
Debug.Assert(dataRead.Length = dataWrite.Length)
i = 0
Do While i < dataRead.Length
Debug.Assert(dataRead(i) = dataWrite(i))
i += 1
Loop
End Sub