←Select platform

StartOverlay Method

Summary
Indicates which method should be called when an overlay is detected inside a file.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (BOOL)startOverlay:(nullable LTCodecsOverlayCallback)callback  
                mode:(LTCodecsOverlayCallbackMode)mode  
               error:(NSError **)error 
public void startOverlay(CodecsOverlayListener listener, CodecsOverlayCallbackMode mode) 
def StartOverlay(self,callback,mode): 

Parameters

callback
The method which should be called when an overlay is detected. Use a null reference to indicate that LEADTOOLS should handle overlays automatically.

mode
Indicates when this method should be called. See CodecsOverlayCallbackMode for possible values.

Remarks

Currently, only PTOCA files are known to use such overlays.

PTOCA files contain file references (i.e. filenames) to external files that contain overlay bitmaps. (These files are typically in IOCA format)

These external overlay files will be resized and placed on the current page according to the information from the PTOCA files. By default, LEADTOOLS will load these external overlay files from disk. You should override this behavior if you load files that are not stored locally (for example, on a remote storage or in a database).

To load overlays stored on other storage, you have to pass your overlay callback to this method and load the overlays in your overlay callback.

The overlay callback will be used until StopOverlay is called.

Example

This example will read a PTOKA file and overlays a TIF file on it

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
void PtokaOverlayExample(string ptokaFileName, string ptokaFilesPath) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Set up the private variables used in the callback 
   myCodecs = codecs; 
   myPtokaFilesPath = ptokaFilesPath; 
 
   // Set the overlay callback 
   codecs.StartOverlay(CodecsOverlayCallback, CodecsOverlayCallbackMode.CallLoad); 
 
   // Load the PTOKA file 
   RasterImage image = codecs.Load(ptokaFileName); 
 
   // Stop the overlay by resetting the old callback. 
   codecs.StopOverlay(); 
 
   // Save the image as TIFF 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "PtokaOverlay.tif"); 
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 1); 
   image.Dispose(); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
RasterCodecs myCodecs; 
string myPtokaFilesPath; 
 
void CodecsOverlayCallback(CodecsOverlayData data) 
{ 
   // Show overlay information 
   Debug.WriteLine("File: {0}", data.FileName); 
   Debug.WriteLine("Page Number: {0}", data.PageNumber); 
   Debug.WriteLine("Info: {0}", data.Info); 
 
   // Construct the overlay file name 
   string overlayFileName = Path.Combine(myPtokaFilesPath, data.FileName); 
 
   if (data.Info) 
   { 
      // Info, we only need to fill in the .InfoXXX members of the data 
      CodecsImageInfo imageInfo = myCodecs.GetInformation(overlayFileName, false); 
      data.InfoWidth = imageInfo.Width; 
      data.InfoHeight = imageInfo.Height; 
      data.InfoXResolution = imageInfo.XResolution; 
      data.InfoYResolution = imageInfo.YResolution; 
   } 
   else 
   { 
      // We need to load the overlay image into the .Image member 
      data.Image = myCodecs.Load(overlayFileName); 
   } 
} 
 
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 ptokaOverlayExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String ptokaFileName = combine(LEAD_VARS_IMAGES_DIR, "jbig.jbg"); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Set up the private variables used in the callback 
   myCodecs = codecs; 
   myPtokaFilesPath = LEAD_VARS_IMAGES_DIR; 
 
   // Set the overlay callback 
   codecs.startOverlay(codecsOverlayCallback, CodecsOverlayCallbackMode.CALL_LOAD); 
 
   // Load the PTOKA file 
   RasterImage image = codecs.load(ptokaFileName); 
 
   // Stop the overlay by resetting the old callback. 
   codecs.stopOverlay(); 
 
   // Save the image as TIFF 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "PtokaOverlay.tif"); 
   codecs.save(image, destFileName, RasterImageFormat.TIF, 1); 
   image.dispose(); 
 
   // Clean up 
   codecs.dispose(); 
} 
 
RasterCodecs myCodecs; 
String myPtokaFilesPath; 
CodecsOverlayListener codecsOverlayCallback = new CodecsOverlayListener() { 
 
   @Override 
   public void onOverlay(CodecsOverlayData data) { 
      // Show overlay information 
      System.out.println("File: " + data.getFileName()); 
      System.out.println("Page Number: " + data.getPageNumber()); 
      System.out.println("Info: " + data.getInfo()); 
 
      // Construct the overlay file name 
      String overlayFileName = combine(myPtokaFilesPath, data.getFileName()); 
 
      if (data.getInfo()) { 
         // Info, we only need to fill in the .InfoXXX members of the data 
         CodecsImageInfo imageInfo = myCodecs.getInformation(overlayFileName, false); 
         data.setInfoWidth(imageInfo.getWidth()); 
         data.setInfoHeight(imageInfo.getHeight()); 
         data.setInfoXResolution(imageInfo.getXResolution()); 
         data.setInfoYResolution(imageInfo.getYResolution()); 
      } else { 
         // We need to load the overlay image into the .Image member 
         data.setImage(myCodecs.load(overlayFileName)); 
      } 
   } 
 
}; 
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.