LEADTOOLS Image Processing (Leadtools.ImageProcessing.Color assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
GrayScaleToDuotoneCommand Class
See Also  Members  



Converts the grayscale image into a colored one by mixing or replacing the original values of the pixels with new colors. This class is available in the Raster Pro and above toolkits. Supported in Silverlight, Windows Phone 7

Object Model

GrayScaleToDuotoneCommand Class

Syntax

Visual Basic (Declaration) 
Public Class GrayScaleToDuotoneCommand 
   Inherits Leadtools.ImageProcessing.RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As GrayScaleToDuotoneCommand
C# 
public class GrayScaleToDuotoneCommand : Leadtools.ImageProcessing.RasterCommand, IRasterCommand  
C++/CLI 
public ref class GrayScaleToDuotoneCommand : public Leadtools.ImageProcessing.RasterCommand, IRasterCommand  

Example

Run the Leadtools.ImageProcessing.Color.GrayScaleToDuotoneCommand on an image.

Visual BasicCopy Code
Public Sub GrayScaleToDuetoneCommandExample()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True

   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg"))

   ' Prepare the command
   Dim command As GrayScaleToDuotoneCommand = New GrayScaleToDuotoneCommand
   'Apply duotone conversion.
   command.Type = GrayScaleToDuotoneCommandMixingType.ReplaceOldWithNew
   command.Color = New RasterColor(255, 0, 0)
   command.Run(leadImage)
   codecs.Save(leadImage, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24)

End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void GrayScaleToDuotoneCommandExample()
   {
      // Load an image
      RasterCodecs codecs = new RasterCodecs();
      codecs.ThrowExceptionsOnInvalidImages = true;

      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg"));

      // Prepare the command
      GrayScaleToDuotoneCommand command = new GrayScaleToDuotoneCommand();
      //Apply duotone conversion.
      command.Type = GrayScaleToDuotoneCommandMixingType.ReplaceOldWithNew;
      command.Color = new Leadtools.RasterColor(255, 0, 0);
      command.Run(image);
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24);

   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
public void GrayScaleToDuotoneCommandExample(RasterImage image, Stream outStream)
{
   // Prepare the command
   GrayScaleToDuotoneCommand command = new GrayScaleToDuotoneCommand();
   //Apply duotone conversion.
   command.Type = GrayScaleToDuotoneCommandMixingType.ReplaceOldWithNew;
   command.Color = new Leadtools.RasterColor(255, 0, 0);
   command.Run(image);
   // Save result image
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);
   image.Dispose();
}
SilverlightVBCopy Code
Public Sub GrayScaleToDuotoneCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)
   ' Prepare the command
   Dim command As GrayScaleToDuotoneCommand = New GrayScaleToDuotoneCommand()
   'Apply duotone conversion.
   command.Type = GrayScaleToDuotoneCommandMixingType.ReplaceOldWithNew
   command.Color = New RasterColor(255, 0, 0)
   command.Run(image)
   ' Save result image
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
   image.Dispose()
End Sub

Remarks

  • This class was designed for use with grayscale images. If the image being used is not grayscale, this method only affects those pixels or areas of the image where Red = Green = Blue.
  • This class transforms the 8-bit grayscale images into colored 8-bit images (Palette) meanwhile the 12-bit and 16-bit grayscale images are transformed into a 48-bit colored image.
  • Monotone conversion is possible by setting GrayScaleToDuotoneCommandMixingType to ReplaceOldWithNew, which clears the palette.
  • This method gives you the option of having the toolkit generate the array of colors to use or creating the array of colors to use yourself.
  • To have the toolkit generate the array of colors, pass the color to use for generating the array of gradient colors in the Color property.
    • If the image is binary, the Leadtools.RasterImage.GrayscaleMode property is used to determine the kind of grayscale palette being used. If the Leadtools.RasterImage.GrayscaleMode property is Leadtools.RasterImage.GrayscaleMode.OrderedInverse or Leadtools.RasterImage.GrayscaleMode.NotOrdered, then the color set in the Color property for the GrayScaleToDuotoneCommand will become the first color in the array generated by the toolkit, NewColor[0], and the toolkit will create the second color in the array NewColor[1]. If the Leadtools.RasterImage.GrayscaleMode property is a value other than Leadtools.RasterImage.GrayscaleMode.OrderedInverse or Leadtools.RasterImage.GrayscaleMode.NotOrdered, then the color set in the Color property for the GrayScaleToDuotoneCommand will become the second color in the array generated by the toolkit, NewColor[1], and the toolkit will create the first color in the array NewColor[0].
    • If the image is grayscale (not binary) the GrayScaleToDuotoneCommand will use the color set in the Color property and generate a 256 color gradient in NewColor.
    • If the image is not grayscale (it is color) then the GrayScaleToDuotoneCommand will use the color set in the Color property and generate a 256 color gradient in NewColor. These colors will be used to change only those pixels in the color image for which Red = Green = Blue.
  • To use a user-defined array of colors:
    • If the image is binary, call GrayScaleToDuotoneCommand with the two colors you wish to use in the NewColor property.
    • If the image is grayscale (not binary) call GrayScaleToDuotoneCommand with the 256 colors you wish to use in the NewColor property.
    • If the image is not grayscale (it is color) call GrayScaleToDuotoneCommand with the 256 colors you wish to use in the NewColor property. These colors will be used to change only those pixels in the color image for which Red = Green = Blue.
  • This class 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 class does not support signed data images.
  • This command does not support 32-bit grayscale images.
For more information, refer to Introduction to Image Processing With LEADTOOLS.
For more information, refer to Grayscale Images.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Color.GrayScaleToDuotoneCommand

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also