LEADTOOLS画像処理(Leadtools.ImageProcessing.Coreアセンブリ)

フレームを表示

ColorizeGrayCommandクラス








メンバ 
8、12または16ビットグレースケールimageに色をつけます。クラスは、24ビットRGB形式に指定された形式からimageのカラービット/ピクセルを変更します。
オブジェクトモデル
構文
'Declaration
 
Public Class ColorizeGrayCommand 
   Inherits Leadtools.ImageProcessing.RasterCommand
   Implements Leadtools.ImageProcessing.IRasterCommand 
'Usage
 
Dim instance As ColorizeGrayCommand
public sealed class ColorizeGrayCommand : Leadtools.ImageProcessing.IRasterCommand  
@interface LTColorizeGrayCommand : LTRasterCommand
public class ColorizeGrayCommand extends RasterCommand
function Leadtools.ImageProcessing.Core.ColorizeGrayCommand()
解説

このクラスは、Imaging Pro以上のツールキットで利用できます。

詳細については、「グレースケールイメージ」を参照してください。

LEADTOOLSのSilverlightバージョンにおいて、RasterImageオブジェクトのための画像データがSilverlight WriteableBitmapを用いて内部的に保存されるならば、この画像処理コマンドは失敗しますオブジェクト。詳細については、「Silverlightの画像処理コマンド限界」を参照してください。

サンプル

このサンプルは16ビットグレースケールimageをロードして、それからそれに色をつけます。

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

   
Public Sub ColorizeGrayCommandExample()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ImageProcessingDemo\Beauty16.jpg"))

   ' Prepare the command
   Dim i As Integer
   Dim pGrayColors() As ColorizeGrayCommandData
   ReDim pGrayColors(5)

   For i = 0 To 5
      pGrayColors(i) = New ColorizeGrayCommandData
   Next

   pGrayColors(0).Threshold = 9999
   pGrayColors(1).Threshold = 19999
   pGrayColors(2).Threshold = 29999
   pGrayColors(3).Threshold = 39999
   pGrayColors(4).Threshold = 49999
   pGrayColors(5).Threshold = 59999

   pGrayColors(0).Color = New RasterColor(255, 0, 0)
   pGrayColors(1).Color = New RasterColor(0, 255, 0)
   pGrayColors(2).Color = New RasterColor(0, 0, 255)
   pGrayColors(3).Color = New RasterColor(0, 255, 255)
   pGrayColors(4).Color = New RasterColor(255, 0, 255)
   pGrayColors(5).Color = New RasterColor(255, 255, 0)

   Dim command As ColorizeGrayCommand = New ColorizeGrayCommand
   command.GrayColors = pGrayColors
   'Call the command
   command.Run(leadImage)

   ' Save the resulted Image
   codecs.Save(command.DestinationImage, Path.Combine(LEAD_VARS.ImagesDir, "ColorizeGrayResult.Bmp"), RasterImageFormat.Bmp, 24)

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.Core;

      
public void ColorizeGrayCommandExample()
{
   // Load an image
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;

   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, @"ImageProcessingDemo\Beauty16.jpg"));

   // Prepare the command
   ColorizeGrayCommandData[] pGrayColors = new ColorizeGrayCommandData[6];
   for (int i = 0; i < 6; i++)
      pGrayColors[i] = new ColorizeGrayCommandData();
   pGrayColors[0].Threshold   = 9999;
   pGrayColors[1].Threshold   = 19999;
   pGrayColors[2].Threshold   = 29999;
   pGrayColors[3].Threshold   = 39999;
   pGrayColors[4].Threshold   = 49999;
   pGrayColors[5].Threshold   = 59999;

   pGrayColors[0].Color       = new RasterColor(255, 0, 0);
   pGrayColors[1].Color       = new RasterColor(0, 255, 0);
   pGrayColors[2].Color       = new RasterColor(0, 0, 255);
   pGrayColors[3].Color       = new RasterColor(0, 255, 255);
   pGrayColors[4].Color       = new RasterColor(255, 0, 255);
   pGrayColors[5].Color       = new RasterColor(255, 255, 0);

   ColorizeGrayCommand command = new ColorizeGrayCommand();
   command.GrayColors = pGrayColors;
   //Call the command
   command.Run(image);

   // Save the resulted image
   codecs.Save(command.DestinationImage, Path.Combine(LEAD_VARS.ImagesDir, "ColorizeGrayResult.Bmp"), RasterImageFormat.Bmp, 24);

}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
function ColorizeGrayCommandExample() {
   var codecs = new Leadtools.Codecs.RasterCodecs();
   codecs.throwExceptionsOnInvalidImages = true;

   // Load the image
   var srcFileName = "Assets\\Beauty16.jpg";
   var destFileName = "ColorizeGrayResult.bmp";
   var saveImage;

   return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
      return codecs.loadAsync(Leadtools.LeadStreamFactory.create(loadFile));
   }).then(function (image) {
      // Prepare the command
      with (Leadtools.ImageProcessing.Core) {
         var pGrayColors = new Array();
         for (var i = 0; i < 6; i++)
            pGrayColors[i] = new ColorizeGrayCommandData();

         pGrayColors[0].threshold = 9999;
         pGrayColors[1].threshold = 19999;
         pGrayColors[2].threshold = 29999;
         pGrayColors[3].threshold = 39999;
         pGrayColors[4].threshold = 49999;
         pGrayColors[5].threshold = 59999;

         pGrayColors[0].color = Leadtools.RasterColorHelper.create(255, 0, 0);
         pGrayColors[1].color = Leadtools.RasterColorHelper.create(0, 255, 0);
         pGrayColors[2].color = Leadtools.RasterColorHelper.create(0, 0, 255);
         pGrayColors[3].color = Leadtools.RasterColorHelper.create(0, 255, 255);
         pGrayColors[4].color = Leadtools.RasterColorHelper.create(255, 0, 255);
         pGrayColors[5].color = Leadtools.RasterColorHelper.create(255, 255, 0);

         var command = new ColorizeGrayCommand();
         command.grayColors = pGrayColors;
         //Call the command
         command.run(image);
         saveImage = command.destinationImage;

         return Tools.AppLocalFolder().createFileAsync(destFileName);
      }
   })
   .then(function (saveFile) {
      // Save the resulted image
      return codecs.saveAsync(saveImage, Leadtools.LeadStreamFactory.create(saveFile), Leadtools.RasterImageFormat.bmp, 24);
   });
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Core;

      
public async Task ColorizeGrayCommandExample()
{
   // Load an image
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;

   // Load the image
   string srcFileName = @"Assets\Beauty16.jpg";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Prepare the command
   ColorizeGrayCommandData[] pGrayColors = new ColorizeGrayCommandData[6];
   for (int i = 0; i < 6; i++)
      pGrayColors[i] = new ColorizeGrayCommandData();
   pGrayColors[0].Threshold   = 9999;
   pGrayColors[1].Threshold   = 19999;
   pGrayColors[2].Threshold   = 29999;
   pGrayColors[3].Threshold   = 39999;
   pGrayColors[4].Threshold   = 49999;
   pGrayColors[5].Threshold   = 59999;

   pGrayColors[0].Color       = RasterColorHelper.Create(255, 0, 0);
   pGrayColors[1].Color       = RasterColorHelper.Create(0, 255, 0);
   pGrayColors[2].Color       = RasterColorHelper.Create(0, 0, 255);
   pGrayColors[3].Color       = RasterColorHelper.Create(0, 255, 255);
   pGrayColors[4].Color       = RasterColorHelper.Create(255, 0, 255);
   pGrayColors[5].Color       = RasterColorHelper.Create(255, 255, 0);

   ColorizeGrayCommand command = new ColorizeGrayCommand();
   command.GrayColors = pGrayColors;
   //Call the command
   command.Run(image);

   // Save the resulted image
   string destFileName = @"ColorizeGrayResult.bmp";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(command.DestinationImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24);
}
using Leadtools;
using Leadtools.Examples;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Core;

public void ColorizeGrayCommandExample(RasterImage image, Stream outStream)
{
   // Prepare the command
   ColorizeGrayCommandData[] pGrayColors = new ColorizeGrayCommandData[6];
   for (int i = 0; i < 6; i++)
      pGrayColors[i] = new ColorizeGrayCommandData();
   pGrayColors[0].Threshold   = 9999;
   pGrayColors[1].Threshold   = 19999;
   pGrayColors[2].Threshold   = 29999;
   pGrayColors[3].Threshold   = 39999;
   pGrayColors[4].Threshold   = 49999;
   pGrayColors[5].Threshold   = 59999;
   pGrayColors[0].Color       = new RasterColor(255, 0, 0);
   pGrayColors[1].Color       = new RasterColor(0, 255, 0);
   pGrayColors[2].Color       = new RasterColor(0, 0, 255);
   pGrayColors[3].Color       = new RasterColor(0, 255, 255);
   pGrayColors[4].Color       = new RasterColor(255, 0, 255);
   pGrayColors[5].Color       = new RasterColor(255, 255, 0);

   ColorizeGrayCommand command = new ColorizeGrayCommand();
   command.GrayColors = pGrayColors;
   //Call the command
   command.Run(image);

   // Save result image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);
   image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing.Core

Public Sub ColorizeGrayCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)
   ' Prepare the command
   Dim pGrayColors As ColorizeGrayCommandData() = New ColorizeGrayCommandData(5){}
   For i As Integer = 0 To 5
      pGrayColors(i) = New ColorizeGrayCommandData()
   Next i
   pGrayColors(0).Threshold = 9999
   pGrayColors(1).Threshold = 19999
   pGrayColors(2).Threshold = 29999
   pGrayColors(3).Threshold = 39999
   pGrayColors(4).Threshold = 49999
   pGrayColors(5).Threshold = 59999
   pGrayColors(0).Color = New RasterColor(255, 0, 0)
   pGrayColors(1).Color = New RasterColor(0, 255, 0)
   pGrayColors(2).Color = New RasterColor(0, 0, 255)
   pGrayColors(3).Color = New RasterColor(0, 255, 255)
   pGrayColors(4).Color = New RasterColor(255, 0, 255)
   pGrayColors(5).Color = New RasterColor(255, 255, 0)

   Dim command As ColorizeGrayCommand = New ColorizeGrayCommand()
   command.GrayColors = pGrayColors
   'Call the command
   command.Run(image)

   ' Save result image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
   image.Dispose()
End Sub
必要条件

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

参照

参照

ColorizeGrayCommandメンバ
Leadtools.ImageProcessing.Core名前空間
グレースケールイメージ
WindowLevelCommandクラス
WindowLevelCommandクラス
Leadtools.ImageProcessing.Color.GrayScaleToDuotoneCommand
Leadtools.ImageProcessing.Color.GrayScaleToMultitoneCommand
ShiftDataCommandクラス
SelectDataCommandクラス
Leadtools.ImageProcessing.Color.AdjustTintCommand
Leadtools.ImageProcessing.Effects.ColorHalftoneCommand