Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
StartDithering Method
See Also  Example
Leadtools Namespace > RasterImage Class : StartDithering Method



palette
The palette this uses for dithering. You can specify your own palette, or use a null reference (Nothing in Visual Basic) for LEAD's fixed palette.
colors
Number of colors used in the palette. If the palette contains more colors, only the first colors colors are used. Valid values are 2 to 256.
Initializes the buffered dithering of an image.

Syntax

Visual Basic (Declaration)  
Public Sub StartDithering( _
   ByVal palette() As RasterColor, _
   ByVal colors As Integer _
) 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim palette() As RasterColor
Dim colors As Integer
 
instance.StartDithering(palette, colors)
C#  
public void StartDithering( 
   RasterColor[] palette,
   int colors
)
C++/CLI  
public:
void StartDithering( 
   array<RasterColor>^ palette,
   int colors
) 

Parameters

palette
The palette this uses for dithering. You can specify your own palette, or use a null reference (Nothing in Visual Basic) for LEAD's fixed palette.
colors
Number of colors used in the palette. If the palette contains more colors, only the first colors colors are used. Valid values are 2 to 256.

Example

This example dithers each line in one image and writes it to another image.

Visual Basic Copy Code
Public Sub StartDitheringExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' Load an image that has BottomLeft ViewPerspective
   Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP")

   Dim Palette As RasterColor() = RasterPalette.Fixed(8)

   ' Create the new palletized image.
   Dim destinationImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height, 8, image.Order, image.ViewPerspective, Palette, IntPtr.Zero, 0)

   ' Set the dithering method.
   image.DitheringMethod = RasterDitheringMethod.StevensonArce

   ' Initialize the dithering process.
   image.StartDithering(Palette, 256)

   ' Allocate the output buffer for 8-bit data.
   Dim InBuffer As Byte() = New Byte(image.Width * 3 - 1) {} ' Buffer to hold the input row.
   Dim OutBuffer As Byte() = New Byte(image.Width - 1) {} ' Buffer to hold the output row.

   ' Use DitherLine method to process each row in the image.
   Dim i As Integer = 0
   Do While i < image.Height
      image.GetRow(i, InBuffer, 0, image.BytesPerLine)
      image.DitherLine(InBuffer, 0, OutBuffer, 0)
      destinationImage.SetRow(i, OutBuffer, 0, destinationImage.BytesPerLine)
      i += 1
   Loop
   ' End the dithering process.
   image.StopDithering()

   codecs.Save(destinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_DitherLine.BMP", RasterImageFormat.Bmp, 0)

   image.Dispose()
   destinationImage.Dispose()
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void StartDitheringExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   // Load an image that has BottomLeft ViewPerspective 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP"); 
 
   RasterColor[] Palette = RasterPalette.Fixed(8); 
 
   // Create the new palletized image. 
   RasterImage destinationImage = new RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height, 8, image.Order, image.ViewPerspective, Palette, IntPtr.Zero, 0); 
 
   // Set the dithering method. 
   image.DitheringMethod = RasterDitheringMethod.StevensonArce; 
 
   // Initialize the dithering process. 
   image.StartDithering(Palette, 256); 
 
   // Allocate the output buffer for 8-bit data. 
   byte[] InBuffer = new byte[image.Width * 3];// Buffer to hold the input row. 
   byte[] OutBuffer = new byte[image.Width];// Buffer to hold the output row. 
 
   // Use DitherLine method to process each row in the image. 
   for(int i = 0; i < image.Height; i++) 
   { 
      image.GetRow(i, InBuffer, 0, image.BytesPerLine); 
      image.DitherLine(InBuffer, 0, OutBuffer, 0); 
      destinationImage.SetRow(i, OutBuffer, 0, destinationImage.BytesPerLine); 
   } 
   // End the dithering process. 
   image.StopDithering(); 
 
   codecs.Save(destinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_DitherLine.BMP", RasterImageFormat.Bmp, 0); 
 
   image.Dispose(); 
   destinationImage.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

The following flow chart shows how the methods relate to each other:

The following properties from the RasterImage are used to control the dithering operation:

This method does not support signed images.

For more information, refer to Introduction to Image Processing With LEADTOOLS.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also