Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, May 5, 2017 3:46:49 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

Was thanked: 9 time(s) in 9 post(s)

Every LEADTOOLS Image Processing command (RotateCommand, AutoBinarizeCommand, and DeskewCommand, to name only a few) all inherit from same basic RasterCommand class. By declaring a new class which inherits from this one, custom image processing can be performed which can use a combination of existing RasterCommands and custom logic as needed.

The member list for the base class is in our documentation. These members can be overridden based on development needs.
https://www.leadtools.com/help/leadtools/v20/dh/l/imageprocessing-rastercommand.html

Here's a quick example of how to create a custom RasterCommand which both flips and mirrors an image. Note this is for example purposes and can be made more complex if need be based on development needs.

Code:

      class FlipAndMirrorCommand : RasterCommand
      {
         private bool isCancelled = false;
         public override void OnProgress(RasterCommandProgressEventArgs e)
         {
            base.OnProgress(e);
            isCancelled = e.Cancel;
         }
         public override RasterImageChangedFlags Run(RasterImage image)
         {
            FlipCommand flip = new FlipCommand();
            RasterImageChangedFlags flags = flip.Run(image);

            OnProgress(new RasterCommandProgressEventArgs(50));
            if (isCancelled)
            {
               return flags;
            }

            flip.Horizontal = true;
            flags |= flip.Run(image);

            return flags;
         }
      }


Of note here is the OnProgress() call which is explicitly called to report the progress to the event handler, and the Run() method which actively performs the logic on the target RasterImage.

Note how OnProgress calls the base implementation--this actually executes the event handler associated with the command, if applicable, then checks to see if the event should be cancelled based on the outcome of the event handler.

The Run() method contains the logic used to actively manipulate the image. In this case, the command is flipping the image vertically first, then flipping the image horizontally, with the progress event (and possibility to cancel) occurring between flips. Note if the operation is cancelled, the image will still be flipped vertically.

Note how the return type for Run() is of RasterImageChangedFlags. This is true for all RasterCommands, but this value is typically discarded. In this case, RasterImageChangedFlags.Data is being returned as the actual image data are being manipulated. This flag is indicates the changes made to the image as a result of the RasterCommand. More information on the available flags are in our documentation.
https://www.leadtools.com/help/leadtools/v20/dh/l/rasterimagechangedflags.html

Here's some simple code on how to instantiate and run this command:

Code:

         using (RasterCodecs codecs = new RasterCodecs())
         {
            RasterImage img = codecs.Load(@"cannon.png");
            RasterCommand cmd = new FlipAndMirrorCommand();
            cmd.Run(img);

            codecs.Save(img, @"cannon-fm.png", img.OriginalFormat, img.BitsPerPixel);
         }

Edited by user Friday, June 1, 2018 11:48:30 AM(UTC)  | Reason: Updating links to v20

Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.109 seconds.