LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

RasterCommandクラス








メンバ 
RasterCommandクラスはIRasterCommandを実装して、すべてのLEADTOOLS画像処理コマンドのためのベースクラスです。
オブジェクトモデル
構文
public abstract class RasterCommand : IRasterCommand  
'Declaration
 
Public MustInherit Class RasterCommand 
   Implements IRasterCommand 
'Usage
 
Dim instance As RasterCommand
public sealed class RasterCommand : IRasterCommand  
@interface LTRasterCommand : NSObject
public abstract class RasterCommand implements IRasterCommand
function Leadtools.ImageProcessing.RasterCommand()
public ref class RasterCommand abstract : public IRasterCommand  
解説

RasterCommandクラスは、すべてのLEADTOOLS画像処理コマンドのためのベースクラスです。

このクラスは、画像処理コマンド(コマンドの進捗ステータスを含む)を実行することで、取引のために機能性を格納します。

サンプル

このサンプルは、進捗パーセンテージを示しているimageの上で、2つの画像処理コマンドを実行します。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing

      
Public Sub RasterCommandExample()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
   Dim rotatedFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_rotated.bmp")
   Dim flippedFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_flipped.bmp")

   ' Load the source image from disk
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' flip the image
   Dim flip As FlipCommand = New FlipCommand(False)
   RunCommand(image, flip)

   ' save the image
   codecs.Save(image, flippedFileName, RasterImageFormat.Bmp, 24)

   ' rotate the image by 45 degrees
   Dim rotate As RotateCommand = 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()
End Sub

Private cancelAt50 As Boolean

Private Sub RunCommand(ByVal image As RasterImage, ByVal command As IRasterCommand)
   ' subscribe to the progress event of the command
   AddHandler command.Progress, AddressOf command_Progress

   ' if this is a flip command, we want to stop at 50 percent
   cancelAt50 = TypeOf command Is FlipCommand

   ' run the command
   command.Run(image)

   RemoveHandler command.Progress, AddressOf command_Progress
End Sub

Private Sub command_Progress(ByVal sender As Object, ByVal e As RasterCommandProgressEventArgs)
   ' show the percentage
   Console.WriteLine(e.Percent)

   ' check if we need to cancel the command at 50%
   If e.Percent = 50 AndAlso cancelAt50 Then
      e.Cancel = True
   End If
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;

      
public void RasterCommandExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string rotatedFileName = Path.Combine(ImagesPath.Path, "Image1_rotated.bmp");
   string flippedFileName = Path.Combine(ImagesPath.Path, "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, IRasterCommand 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;
}
RasterCommandExamples.prototype.RasterCommandExample = function () {
    Tools.SetLicense();

    with (Leadtools) {
        with (Leadtools.Codecs) {
            var codecs = new RasterCodecs();

            var srcFileName = "Assets\\Image1.cmp";
            var rotatedFileName = "Image1_rotated.bmp";
            var flippedFileName = "Image1_flipped.bmp";
            var srcImage;
            // Load the image
            return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
                return codecs.loadAsync(LeadStreamFactory.create(loadFile), 24, CodecsLoadByteOrder.bgr, 1, 1)
            })
            .then(function (img) {
                srcImage = img;

                // flip the image
                var flip = new Leadtools.ImageProcessing.FlipCommand(false);
                RunCommand(srcImage, flip);

                // save the flipped image
                return Tools.AppLocalFolder().createFileAsync(flippedFileName)
            })
            .then(function (saveFile) {
                return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, 24)
            })
            .then(function () {

                // rotate the image by 45 degrees
                var rotate = new Leadtools.ImageProcessing.RotateCommand();
                rotate.angle = 45 * 100;
                rotate.fillColor = RasterColorHelper.fromKnownColor(RasterKnownColor.white);
                rotate.flags = Leadtools.ImageProcessing.RotateCommandFlags.resize;
                RunCommand(srcImage, rotate);
                
                // save the rotated image
                return Tools.AppLocalFolder().createFileAsync(rotatedFileName)
            })
            .then(function (saveFile) {
                return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, 24)
            })
            .then(function () {
                // clean up
                srcImage.close();
                codecs.close();
            });
        }
    }
}

var cancelAt50;

function RunCommand(image, command)
{
    // subscribe to the progress event of the command
    command.addEventListener ( "progress", command_Progress ) ;
    
    // if this is a flip command, we want to stop at 50 percent
    cancelAt50 = command instanceof Leadtools.ImageProcessing.FlipCommand ;

    // run the command
    command.run(image);

    command.removeEventListener("progress", command_Progress);
}


function command_Progress(e)
{
    // show the percentage
             console.info(e.percent);

    // check if we need to cancel the command at 50%
    if (e.percent === 50 && cancelAt50)
        e.cancel = true;
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;

      
public async Task RasterCommandExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string rotatedFileName = @"Image1_rotated.bmp";
   string flippedFileName = @"Image1_flipped.bmp";

   // Load the image
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 24, CodecsLoadByteOrder.Bgr, 1, 1);

   // flip the image
   FlipCommand flip = new FlipCommand(false);
   RunCommand(srcImage, flip);

   // save the flipped image
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(flippedFileName);
   await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24);

   // rotate the image by 45 degrees
   RotateCommand rotate = new RotateCommand();
   rotate.Angle = 45 * 100;
   rotate.FillColor = RasterColorHelper.FromKnownColor(RasterKnownColor.White);
   rotate.Flags = RotateCommandFlags.Resize;
   RunCommand(srcImage, rotate);

   // save the rotated image
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(rotatedFileName);
   await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24);

   // clean up
   srcImage.Dispose();
}

bool cancelAt50;

void RunCommand(RasterImage image, IRasterCommand 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
   Debug.WriteLine(e.Percent);

   // check if we need to cancel the command at 50%
   if (e.Percent == 50 && cancelAt50)
      e.Cancel = true;
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;
using Leadtools.Windows.Media;

public void RasterCommandExample(RasterImage image, Stream flippedStream, Stream rotatedStream)
{
   RasterCodecs codecs = new RasterCodecs();
   // flip the image
   FlipCommand flip = new FlipCommand(false);
   RunCommand(image, flip);

   // save the image
   codecs.Save(image, flippedStream, RasterImageFormat.Png, 24);

   // rotate the image by 45 degrees
   RotateCommand rotate = new RotateCommand();
   rotate.Angle = 45 * 100;
   rotate.FillColor = RasterColorConverter.FromColor(Colors.White);
   rotate.Flags = RotateCommandFlags.Resize;
   RunCommand(image, rotate);

   // save the image
   codecs.Save(image, rotatedStream, RasterImageFormat.Png, 24);

   // clean up
   image.Dispose();
}

bool cancelAt50;

void RunCommand(RasterImage image, IRasterCommand 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
   Debug.WriteLine(e.Percent);

   // check if we need to cancel the command at 50%
   if(e.Percent == 50 && cancelAt50)
      e.Cancel = true;
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.Windows.Media

Public Sub RasterCommandExample(ByVal image As RasterImage, ByVal flippedStream As Stream, ByVal rotatedStream As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' flip the image
   Dim flip As FlipCommand = New FlipCommand(False)
   RunCommand(image, flip)

   ' save the image
   codecs.Save(image, flippedStream, RasterImageFormat.Png, 24)

   ' rotate the image by 45 degrees
   Dim rotate As RotateCommand = New RotateCommand()
   rotate.Angle = 45 * 100
   rotate.FillColor = RasterColorConverter.FromColor(Colors.White)
   rotate.Flags = RotateCommandFlags.Resize
   RunCommand(image, rotate)

   ' save the image
   codecs.Save(image, rotatedStream, RasterImageFormat.Png, 24)

   ' clean up
   image.Dispose()
End Sub

Private cancelAt50 As Boolean

Private Sub RunCommand(ByVal image As RasterImage, ByVal command As IRasterCommand)
   ' subscribe to the progress event of the command
   AddHandler command.Progress, AddressOf command_Progress

   ' if this is a flip command, we want to stop at 50 percent
   cancelAt50 = TypeOf command Is FlipCommand

   ' run the command
   command.Run(image)

   RemoveHandler command.Progress, AddressOf command_Progress
End Sub

Private Sub command_Progress(ByVal sender As Object, ByVal e As RasterCommandProgressEventArgs)
   ' show the percentage
   Debug.WriteLine(e.Percent)

   ' check if we need to cancel the command at 50%
   If e.Percent = 50 AndAlso cancelAt50 Then
      e.Cancel = True
   End If
End Sub
必要条件

ターゲットプラットホーム

参照

参照

RasterCommandメンバ
Leadtools.ImageProcessing名前空間