Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
ColorResolutionCommandDataEventArgs Class
See Also  Members   Example 
Leadtools.ImageProcessing Namespace : ColorResolutionCommandDataEventArgs Class



Provides data for the ColorResolutionCommand.Data event.

Object Model


Syntax

Visual Basic (Declaration) 
Public Class ColorResolutionCommandDataEventArgs 
   Inherits EventArgs
Visual Basic (Usage)Copy Code
Dim instance As ColorResolutionCommandDataEventArgs
C# 
public class ColorResolutionCommandDataEventArgs : EventArgs 
C++/CLI 
public ref class ColorResolutionCommandDataEventArgs : public EventArgs 

Example

This example will convert an image from 24 to 1 bits/pixel saving the data into an external image manually

Visual BasicCopy Code
Public Sub ColorResolutionCommandDataEventArgsExample()
 RasterCodecs.Startup()
 Dim codecs As RasterCodecs = New RasterCodecs()

 Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
 Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_colorresData.bmp"

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

 ' Create the destination image
 _row = 0
 _destImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 1, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)

 ' Color-res the image to 1 bits/pixel, we will save the data ourselves into
 ' the destination image
 Dim command As ColorResolutionCommand = New ColorResolutionCommand()
 command.BitsPerPixel = 1
 command.DitheringMethod = RasterDitheringMethod.FloydStein
 AddHandler command.Data, AddressOf command_Data
 command.Run(srcImage)
 RemoveHandler command.Data, AddressOf command_Data

 ' Save it to disk
 codecs.Save(_destImage, destFileName, RasterImageFormat.Bmp, 4)
 _destImage.Dispose()

 ' Clean Up
 srcImage.Dispose()
 RasterCodecs.Shutdown()
      End Sub

      Private _destImage As RasterImage
      Private _row As Integer

      Private Sub command_Data(ByVal sender As Object, ByVal e As ColorResolutionCommandDataEventArgs)
 ' Set the data into the destination image
 _destImage.SetRow(_row, e.Data, _destImage.BytesPerLine * e.Lines)
 _row += e.Lines

 ' If you want the data in a managed buffer,
 ' you can do this
 ' byte[] data = new byte[_destImage.BytesPerLine * e.Lines];
 ' System.Runtime.InteropServices.Marshal.Copy(e.Data, data, 0, data.Length);
      End Sub
C#Copy Code
public void ColorResolutionCommandDataEventArgsExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_colorresData.bmp"; 
 
   // Load the source image from disk 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   // Create the destination image 
   _row = 0; 
   _destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      srcImage.Width, 
      srcImage.Height, 
      1, 
      RasterByteOrder.Rgb, 
      RasterViewPerspective.TopLeft, 
      null, 
      IntPtr.Zero, 
      0); 
 
   // Color-res the image to 1 bits/pixel, we will save the data ourselves into 
   // the destination image 
   ColorResolutionCommand command = new ColorResolutionCommand(); 
   command.BitsPerPixel = 1; 
   command.DitheringMethod = RasterDitheringMethod.FloydStein; 
   command.Data += new EventHandler<ColorResolutionCommandDataEventArgs>(command_Data); 
   command.Run(srcImage); 
   command.Data -= new EventHandler<ColorResolutionCommandDataEventArgs>(command_Data); 
 
   // Save it to disk 
   codecs.Save(_destImage, destFileName, RasterImageFormat.Bmp, 4); 
   _destImage.Dispose(); 
 
   // Clean Up 
   srcImage.Dispose(); 
   RasterCodecs.Shutdown(); 

 
RasterImage _destImage; 
int _row; 
 
void command_Data(object sender, ColorResolutionCommandDataEventArgs e) 

   // Set the data into the destination image 
   _destImage.SetRow(_row, e.Data, _destImage.BytesPerLine * e.Lines); 
   _row += e.Lines; 
 
   // If you want the data in a managed buffer, 
   // you can do this 
   // byte[] data = new byte[_destImage.BytesPerLine * e.Lines]; 
   // System.Runtime.InteropServices.Marshal.Copy(e.Data, data, 0, data.Length); 
}

Inheritance Hierarchy

System.Object
   System.EventArgs
      Leadtools.ImageProcessing.ColorResolutionCommandDataEventArgs

Requirements

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

See Also