←Select platform

RasterMetadataURational Structure

Summary
Encapsulates an unsigned rational value, for use with classes derived from RasterMetadata.
Syntax
C#
Objective-C
C++/CLI
Java
Python
[SerializableAttribute()] 
public struct RasterMetadataURational 
typedef struct LTRasterMetadataURational 
public final class RasterMetadataURational 
[SerializableAttribute()] 
public value class RasterMetadataURational : public System.ValueType  
class RasterMetadataURational: 
Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
 
public void RasterTagMetadataExample() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
	codecs.ThrowExceptionsOnInvalidImages = true; 
 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_tags.tif"); 
 
	// Load the image 
	RasterImage image = codecs.Load(srcFileName); 
 
	// add the tags 
	const int tagSoftware = 0x8001; 
 
	RasterTagMetadata tag; 
 
	// Ascii 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Ascii; 
	tag.FromAscii("Test String"); 
	image.Tags.Add(tag); 
 
	// Byte 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Byte; 
	byte[] byteArray = new byte[1]; 
	byteArray[0] = 10; 
	tag.FromByte(byteArray); 
	image.Tags.Add(tag); 
 
	// SByte 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.SByte; 
	sbyte[] sbyteArray = new sbyte[1]; 
	sbyteArray[0] = -45; 
	tag.FromSByte(sbyteArray); 
	image.Tags.Add(tag); 
 
	// Int16 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Int16; 
	short[] shortArray = new short[1]; 
	shortArray[0] = 64; 
	tag.FromInt16(shortArray); 
	image.Tags.Add(tag); 
 
	// Uint16 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.UInt16; 
	ushort[] uint16Array = new ushort[1]; 
	uint16Array[0] = 50; 
	tag.FromUInt16(uint16Array); 
	image.Tags.Add(tag); 
 
	// Int32 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Int32; 
	int[] intArray = new int[1]; 
	intArray[0] = -1326; 
	tag.FromInt32(intArray); 
	image.Tags.Add(tag); 
 
	// Uint32 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.UInt32; 
	uint[] uintArray = new uint[1]; 
	uintArray[0] = 1326; 
	tag.FromUInt32(uintArray); 
	image.Tags.Add(tag); 
 
	// single 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Single; 
	float[] singleArray = new float[1]; 
	singleArray[0] = 4.53f; 
	tag.FromSingle(singleArray); 
	image.Tags.Add(tag); 
 
	// Double 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Double; 
	double[] doubleArray = new double[1]; 
	doubleArray[0] = 7.1; 
	tag.FromDouble(doubleArray); 
	image.Tags.Add(tag); 
 
	// Rational 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.Rational; 
	RasterMetadataRational[] rational = new RasterMetadataRational[1]; 
	rational[0] = new RasterMetadataRational(); 
	rational[0].Numerator = 3; 
	rational[0].Denominator = 2; 
	tag.FromRational(rational); 
	image.Tags.Add(tag); 
 
	// URational 
	tag = new RasterTagMetadata(); 
	tag.Id = tagSoftware; 
	tag.DataType = RasterTagMetadataDataType.URational; 
	RasterMetadataURational[] urational = new RasterMetadataURational[1]; 
	urational[0] = new RasterMetadataURational(3, 2); 
	tag.FromURational(urational); 
	image.Tags.Add(tag); 
 
	// Save the image and its tags to the destination tiff file 
	codecs.Options.Save.Tags = true; 
	codecs.Save(image, destFileName, RasterImageFormat.Tif, 1); 
 
	// Enumerate the tags from the file 
	codecs.TagFound += new EventHandler<CodecsEnumTagsEventArgs>(codecs_TagFound); 
	codecs.EnumTags(destFileName, 1); 
 
	// clean up 
	image.Dispose(); 
	codecs.Dispose(); 
} 
 
void codecs_TagFound(object sender, CodecsEnumTagsEventArgs e) 
{ 
	Console.WriteLine("Found tag id = {0}, count = {1}, type = {2}", e.Id, e.Count, e.MetadataType); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.InputStream; 
 
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 rasterTagMetadataExample() throws FileNotFoundException { 
   final String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.setThrowExceptionsOnInvalidImages(true); 
 
   String srcFileName = combine(LEAD_VARS_ImagesDir, "Image1.cmp"); 
   String destFileName = combine(LEAD_VARS_ImagesDir, "Image1_tags.tif"); 
 
   // Load the image 
   RasterImage image = codecs.load(srcFileName); 
 
   // Add the tags 
   final int tagSoftware = 0x8001; 
 
   RasterTagMetadata tag; 
 
   // Ascii 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.ASCII); 
   tag.fromAscii("Test String"); 
 
   image.getTags().add(tag); 
 
   // Byte 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.BYTE); 
   byte[] byteArray = new byte[1]; 
   byteArray[0] = 10; 
   tag.fromByte(byteArray); 
   image.getTags().add(tag); 
 
   // SByte 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.SBYTE); 
   byte[] sbyteArray = new byte[1]; 
   byteArray[0] = -45; 
   tag.fromSByte(sbyteArray); 
   image.getTags().add(tag); 
 
   // Int16 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.INT_16); 
   short[] shortArray = new short[1]; 
   shortArray[0] = 64; 
   tag.fromInt16(shortArray); 
   image.getTags().add(tag); 
 
   // Uint16 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.INT_32); 
   int[] uint16Array = new int[1]; 
   uint16Array[0] = 4; 
   tag.fromInt32(uint16Array); 
   image.getTags().add(tag); 
 
   // Int32 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.INT_32); 
   int[] intArray = new int[1]; 
   intArray[0] = -1326; 
   tag.fromInt32(intArray); 
   image.getTags().add(tag); 
 
   // Uint32 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.INT_32); 
   int[] uintArray = new int[1]; 
   uintArray[0] = 1326; 
   tag.fromInt32(uintArray); 
   image.getTags().add(tag); 
 
   // Float 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.SINGLE); 
   float[] singleArray = new float[1]; 
   singleArray[0] = 4.53f; 
   tag.fromSingle(singleArray); 
   image.getTags().add(tag); 
 
   // Double 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.DOUBLE); 
   double[] doubleArray = new double[1]; 
   doubleArray[0] = 7.1; 
   tag.fromDouble(doubleArray); 
   image.getTags().add(tag); 
 
   // Rational 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.RATIONAL); 
   RasterMetadataRational[] rational = new RasterMetadataRational[1]; 
   rational[0] = new RasterMetadataRational(3, 2); 
   tag.fromRational(rational); 
   image.getTags().add(tag); 
 
   // URational 
   tag = new RasterTagMetadata(); 
   tag.setId(tagSoftware); 
   tag.setDataType(RasterTagMetadataDataType.URATIONAL); 
   RasterMetadataURational[] urational = new RasterMetadataURational[1]; 
   urational[0] = new RasterMetadataURational(3, 2); 
   tag.fromURational(urational); 
   image.getTags().add(tag); 
 
   // Save the image and its tags to the destination tiff file 
   codecs.getOptions().getSave().setTags(true); 
   codecs.save(image, destFileName, RasterImageFormat.TIF, 1); 
 
   assertTrue("Image unsuccessfully saved", new File(destFileName).exists()); 
   System.out.printf("Commands run, image saved to %s", destFileName); 
 
   // Enumerate the tags from the file 
   codecs.addTagFoundListener(new CodecsTagFoundListener() { 
 
      @Override 
      public void onTagFound(CodecsEnumTagsEvent e) { 
 
         System.out.printf("Found tag id = %s, count = %s, type = %s", e.getId(), e.getCount(), e.getMetadataType()); 
 
      } 
 
   }); 
 
   File file = new File(destFileName); 
   InputStream is = new FileInputStream(file); 
   LeadStream ls = new LeadStream(is, false); 
   codecs.enumTags(ls, 1); 
   assertTrue("File failed to save", file.exists()); 
   System.out.println("The file exists"); 
 
   // clean up 
   image.dispose(); 
   codecs.dispose(); 
} 
Requirements

Target Platforms

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

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