←Select platform

WriteMarker(Stream,int,RasterMarkerMetadata) Method

Summary
Writes a marker to an existing stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void WriteMarker( 
   Stream stream, 
   int pageNumber, 
   RasterMarkerMetadata marker 
) 
- (BOOL)writeMarker:(nullable LTRasterMarkerMetadata *)marker  
           toStream:(LTLeadStream *)stream  
         pageNumber:(NSInteger)pageNumber  
              error:(NSError **)error 
public void writeMarker(ILeadStream stream, int pageNumber, RasterMarkerMetadata marker) 
public: 
void WriteMarker(  
   Stream^ stream, 
   int pageNumber, 
   RasterMarkerMetadata^ marker 
)  
def WriteMarker(self,stream,pageNumber,marker): 

Parameters

stream
A Stream containing the output file data.

pageNumber
1-based index of the page at which to write the marker.

marker
A RasterMarkerMetadata object that contains the marker data.

Remarks

For Exif files, this metadata collection will contain all the Exif and GPS comments, stored in APP1. It will also contain the audio information stored in APP2.

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.

Only JPEG and Exif JPEG files support writing markers.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
void MarkersExample(string srcFileName, string destFileName) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Load the source image with markers 
   Debug.WriteLine("Loading the source image with all markers"); 
   codecs.Options.Load.Markers = true; 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   // Show the markers loaded 
   Debug.WriteLine("These markers were loaded:"); 
   foreach (RasterMarkerMetadata marker in srcImage.Markers) 
   { 
      byte[] data = marker.GetData(); 
      codecs.WriteMarker(srcFileName, 1, marker); 
      // codecs.WriteMarker(stream, 1, marker); 
      codecs.WriteTransformMarker(marker.Id, data, 0, 1); 
      Debug.WriteLine(" {0}, DataSize:{1}", marker.Id, data.Length); 
   } 
 
   // Create the destination image 
   RasterImage destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      320, 
      20, 
      24, 
      RasterByteOrder.Bgr, 
      RasterViewPerspective.TopLeft, 
      null, 
      IntPtr.Zero, 
      0); 
 
   // Save this as JPEG 
   codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24); 
 
   // Write the markers from the source image to this destination image 
   Debug.WriteLine("Writing the markers to the destination file"); 
   codecs.WriteMarkers(destFileName, 1, srcImage.Markers); 
 
   srcImage.Dispose(); 
   destImage.Dispose(); 
 
   // Re-load the destination image with markers 
   Debug.WriteLine("Loading the destination image with all markers"); 
   codecs.Options.Load.Markers = true; 
   destImage = codecs.Load(destFileName); 
 
   // Show the markers loaded 
   Debug.WriteLine("These markers were loaded:"); 
   foreach (RasterMarkerMetadata marker in destImage.Markers) 
   { 
      byte[] data = marker.GetData(); 
      Debug.WriteLine(" {0}, DataSize:{1}", marker.Id, data.Length); 
   } 
 
   destImage.Dispose(); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
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 markersExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "ocr1-4.tif"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "markersExampleOutput.tif"); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Load the source image with markers 
   System.out.println("Loading the source image with all markers"); 
   codecs.getOptions().getLoad().setMarkers(true); 
   RasterImage srcImage = codecs.load(srcFileName); 
 
   // Show the markers loaded 
   System.out.println("These markers were loaded:"); 
   for (RasterMarkerMetadata marker : srcImage.getMarkers()) { 
      byte[] data = marker.getData(); 
      ILeadStream srcFileStream = LeadStreamFactory.create(srcFileName); 
      codecs.writeMarker(srcFileStream, 1, marker); 
      // codecs.WriteMarker(stream, 1, marker); 
      codecs.writeTransformMarker(marker.getId(), data, 0, 1); 
      System.out.printf(" %s, DataSize:%s%n", marker.getId(), data.length); 
      srcFileStream.close(); 
   } 
 
   // Create the destination image 
   byte[] byteZero = new byte[0]; 
   RasterImage destImage = new RasterImage(RasterMemoryFlags.CONVENTIONAL.getValue(), 320, 20, 24, 
         RasterByteOrder.BGR, RasterViewPerspective.TOP_LEFT, 
         null, byteZero, 0); 
 
   // Save this as JPEG 
   codecs.save(destImage, destFileName, RasterImageFormat.JPEG, 24); 
 
   // Write the markers from the source image to this destination image 
   System.out.println("Writing the markers to the destination file"); 
   ILeadStream destFileStream = LeadStreamFactory.create(destFileName); 
   codecs.writeMarkers(destFileStream, 1, srcImage.getMarkers()); 
 
   srcImage.dispose(); 
   destImage.dispose(); 
 
   // Re-load the destination image with markers 
   System.out.println("Loading the destination image with all markers"); 
   codecs.getOptions().getLoad().setMarkers(true); 
   destImage = codecs.load(destFileName); 
 
   // Show the markers loaded 
   System.out.println("These markers were loaded:"); 
   for (RasterMarkerMetadata marker : destImage.getMarkers()) { 
      byte[] data = marker.getData(); 
      System.out.printf(" %s, DataSize:%s%n", marker.getId(), data.length); 
   } 
 
   destImage.dispose(); 
 
   // Clean up 
   destFileStream.close(); 
   codecs.dispose(); 
} 
Requirements

Target Platforms

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

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