←Select platform

RasterCommand Class

Summary
The RasterCommand class is the base class for all LEADTOOLS image processing commands.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public abstract class RasterCommand  
@interface LTRasterCommand : NSObject 
public abstract class RasterCommand  
public ref class RasterCommand abstract    
class RasterCommand: 
Remarks

The RasterCommand class is the base class for all LEADTOOLS image processing commands.

This class contains functionality for dealing with running an image processing command, including progress status of the command.

Example

This example runs two image processing commands on an image showing the progress percentage.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
 
 
public void RasterCommandExample() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
	string rotatedFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_rotated.bmp"); 
	string flippedFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_flipped.bmp"); 
 
	// Load the source image from disk 
	RasterImage image = codecs.Load(srcFileName); 
 
	// flip the image 
	FlipCommand flip = new FlipCommand(false); 
	RunCommand(image, flip); 
 
	// save the image 
	codecs.Save(image, flippedFileName, RasterImageFormat.Bmp, 24); 
 
	// rotate the image by 45 degrees 
	RotateCommand rotate = new RotateCommand(); 
	rotate.Angle = 45 * 100; 
	rotate.FillColor = RasterColor.FromKnownColor(RasterKnownColor.White); 
	rotate.Flags = RotateCommandFlags.Resize; 
	RunCommand(image, rotate); 
 
	// save the image 
	codecs.Save(image, rotatedFileName, RasterImageFormat.Bmp, 24); 
 
	// clean up 
	image.Dispose(); 
	codecs.Dispose(); 
} 
 
bool cancelAt50; 
 
void RunCommand(RasterImage image, RasterCommand command) 
{ 
	// subscribe to the progress event of the command 
	command.Progress += new EventHandler<RasterCommandProgressEventArgs>(command_Progress); 
 
	// if this is a flip command, we want to stop at 50 percent 
	cancelAt50 = command is FlipCommand; 
 
	// run the command 
	command.Run(image); 
 
	command.Progress -= new EventHandler<RasterCommandProgressEventArgs>(command_Progress); 
} 
 
void command_Progress(object sender, RasterCommandProgressEventArgs e) 
{ 
	// show the percentage 
	Console.WriteLine(e.Percent); 
 
	// check if we need to cancel the command at 50% 
	if (e.Percent == 50 && cancelAt50) 
		e.Cancel = true; 
} 
 
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.*; 
import leadtools.imageprocessing.*; 
 
 
public void rasterCommandExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "rgsref.cmp"); 
   String rotatedFileName = combine(LEAD_VARS_IMAGES_DIR, "rgsref_rotated.bmp"); 
   String flippedFileName = combine(LEAD_VARS_IMAGES_DIR, "rgsref_flipped.bmp"); 
 
   // Load the source image from disk 
   RasterImage image = codecs.load(srcFileName); 
 
   // flip the image 
   FlipCommand flip = new FlipCommand(false); 
   runCommand(image, flip); 
 
   // save the image 
   codecs.save(image, flippedFileName, RasterImageFormat.BMP, 24); 
 
   // rotate the image by 45 degrees 
   RotateCommand rotate = new RotateCommand(); 
   rotate.setAngle(45 * 100); 
   rotate.setFillColor(RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
   rotate.setFlags(RotateCommandFlags.RESIZE.getValue()); 
   runCommand(image, rotate); 
 
   // save the image 
   codecs.save(image, rotatedFileName, RasterImageFormat.BMP, 24); 
 
   assertTrue("file unsuccessfully saved to " + rotatedFileName, (new File(rotatedFileName)).exists()); 
   System.out.printf("File saved successfully to %s%n", rotatedFileName); 
 
   // clean up 
   image.dispose(); 
   codecs.dispose(); 
} 
 
boolean cancelAt50; 
 
void runCommand(RasterImage image, RasterCommand command) { 
 
   // subscribe to the progress event of the command 
   command.addProgressListener(command_Progress); 
 
   // if this is a flip command, we want to stop at 50 percent 
   cancelAt50 = (command instanceof FlipCommand); 
 
   // run the command 
   command.run(image); 
 
   command.removeProgressListener(command_Progress); 
 
} 
 
RasterImageProgressListener command_Progress = new RasterImageProgressListener() { 
 
   @Override 
   public void RasterImageProgressAlert(RasterImageProgressEvent e) { 
      // show the percentage 
      System.out.println(e.getPercentComplete()); 
 
      // check if we need to cancel the command at 50% 
      if (e.getPercentComplete() == 50 && cancelAt50) 
         e.setCancel(true); 
   } 
 
}; 
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 Assembly

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