←Select platform

ColorResolutionCommandDataEventArgs Class

Summary
Provides data for the ColorResolutionCommand.Data event.
Syntax
C#
C++/CLI
Java
Python
public class ColorResolutionCommandDataEventArgs : EventArgs 
public class ColorResolutionCommandDataEvent extends LeadEvent 
public ref class ColorResolutionCommandDataEventArgs : public System.EventArgs  
class ColorResolutionCommandDataEventArgs(EventArgs): 
Example

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

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
 
 
public void ColorResolutionCommandDataEventArgsExample() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "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); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.*; 
 
 
public void colorResolutionCommandDataEventArgsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "rgsref.cmp"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "rgsref_colorresData.bmp"); 
 
   // Load the source image from disk 
   RasterImage srcImage = codecs.load(srcFileName); 
 
   // Create the destination image 
   byte[] userData = new byte[0]; 
   _row = 0; 
   _destImage = new RasterImage(RasterMemoryFlags.CONVENTIONAL.getValue(), srcImage.getWidth(), srcImage.getHeight(), 
         1, RasterByteOrder.RGB, RasterViewPerspective.TOP_LEFT, null, userData, 0); 
 
   // Color-res the image to 1 bits/pixel, we will save the data ourselves into 
   // the destination image 
   ColorResolutionCommand command = new ColorResolutionCommand(); 
   command.setBitsPerPixel(1); 
   command.setDitheringMethod(RasterDitheringMethod.FLOYD_STEIN); 
   command.addColorResolutionCommandDataListener(command_Data); 
   _destImage.access(); 
   command.run(srcImage); 
   _destImage.release(); 
   command.removeColorResolutionCommandDataListener(command_Data); 
 
   // Save it to disk 
   codecs.save(_destImage, destFileName, RasterImageFormat.BMP, 4); 
 
   assertTrue("file unsuccessfully saved to " + destFileName, (new File(destFileName)).exists()); 
   System.out.printf("File saved successfully to %s%n", destFileName); 
 
   // Clean Up 
   _destImage.dispose(); 
   srcImage.dispose(); 
   codecs.dispose(); 
} 
 
RasterImage _destImage; 
int _row; 
 
ColorResolutionCommandDataListener command_Data = new ColorResolutionCommandDataListener() { 
 
   @Override 
   public void onData(ColorResolutionCommandDataEvent e) { 
      // Set the data into the destination image 
      _destImage.setRow(_row, e.getData(), _destImage.getBytesPerLine() * e.getLines()); 
      _row += e.getLines(); 
   } 
 
}; 
Requirements

Target Platforms

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

Leadtools Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.