CropCommand Class
Summary
Crops the image, resulting in an image having the size of the specified rectangle.
Syntax
C#
VB
Objective-C
C++
Java
@interface LTKernelCropCommand : LTRasterCommand
public class CropCommand extends RasterCommand
Example
This command supports 12- and 16-bit grayscale and 48- and 64-bit color images. Support for 12- and 16-bit grayscale and 48- and 64-bit color images is available only in the Document/Medical toolkits.
This command supports unsigned data images, but not signed ones.
This command does not support 32-bit grayscale images.
This function can only process entire images. It does not support regions.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Kernel;
public void CropCommandExample()
{
using (RasterCodecs codecs = new RasterCodecs())
{
// Load an image
using (RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")))
{
// Prepare the command
Leadtools.ImageProcessing.Kernel.CropCommand command = new Leadtools.ImageProcessing.Kernel.CropCommand();
// Crop 100 pixels from each side of the image
command.CropRect = new LeadRect(
100,
100,
image.Width - 100,
image.Height - 100);
command.Run(image);
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.bmp"), RasterImageFormat.Bmp, 24);
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing.Kernel
Public Sub CopyImageCommandExample()
Using codecs As RasterCodecs = New RasterCodecs()
Using image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))
' Prepare the command
Dim command As CropCommand = New CropCommand()
' Crop 100 pixels from each side of the image
command.CropRect = New LeadRect(
100,
100,
image.Width - 100,
image.Height - 100)
command.Run(image)
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.bmp"), RasterImageFormat.Bmp, 24)
End Using
End Using
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"
End Class