←Select platform

ColorResolutionCommandDataEventArgs Class

Summary

Provides data for the ColorResolutionCommand.Data event.

Syntax
C#
VB
C++
Java
public class ColorResolutionCommandDataEventArgs : EventArgs 
Public Class ColorResolutionCommandDataEventArgs  
   Inherits System.EventArgs 
public class ColorResolutionCommandDataEvent extends LeadEvent 
public ref class ColorResolutionCommandDataEventArgs : public System.EventArgs  

Example

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

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using LeadtoolsExamples.Common; 
 
public void ColorResolutionCommandDataEventArgsExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp"); 
   string destFileName = Path.Combine(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); 
   _destImage.Access(); 
   command.Run(srcImage); 
   _destImage.Release(); 
   command.Data -= new EventHandler<ColorResolutionCommandDataEventArgs>(command_Data); 
 
   // Save it to disk 
   codecs.Save(_destImage, destFileName, RasterImageFormat.Bmp, 4); 
 
   // Clean Up 
   _destImage.Dispose(); 
   srcImage.Dispose(); 
   codecs.Dispose(); 
} 
 
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); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
 
Public Sub ColorResolutionCommandDataEventArgsExample() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") 
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "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 
   _destImage.Access() 
   command.Run(srcImage) 
   _destImage.Release() 
   RemoveHandler command.Data, AddressOf command_Data 
 
   ' Save it to disk 
   codecs.Save(_destImage, destFileName, RasterImageFormat.Bmp, 4) 
   _destImage.Dispose() 
 
   ' Clean Up 
   srcImage.Dispose() 
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 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
c#[Silverlight C# Example] 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Examples; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Media; 
 
public void ColorResolutionCommandDataEventArgsExample(RasterImage srcImage, Stream destStream) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Create the destination image 
   _row = 0; 
   _destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      srcImage.Width, 
      srcImage.Height, 
      1, 
      RasterByteOrder.Rgb, 
      RasterViewPerspective.TopLeft, 
      null, 
      null, 
      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, destStream, RasterImageFormat.Bmp, 4); 
   _destImage.Dispose(); 
 
   // Clean Up 
   srcImage.Dispose(); 
} 
 
RasterImage _destImage; 
int _row; 
 
void command_Data(object sender, ColorResolutionCommandDataEventArgs e) 
{ 
   // Set the data into the destination image 
   _destImage.SetRow(_row, e.DataArray, 0, _destImage.BytesPerLine * e.Lines); 
   _row += e.Lines; 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Windows.Media 
 
Public Sub ColorResolutionCommandDataEventArgsExample(ByVal srcImage As RasterImage, ByVal destStream As Stream) 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' Create the destination image 
   _row = 0 
   _destImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 1, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, Nothing, Nothing, 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, destStream, RasterImageFormat.Bmp, 4) 
   _destImage.Dispose() 
 
   ' Clean Up 
   srcImage.Dispose() 
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.DataArray, 0, _destImage.BytesPerLine * e.Lines) 
   _row += e.Lines 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly