public class ColorResolutionCommandDataEventArgs : EventArgs Public Class ColorResolutionCommandDataEventArgsInherits System.EventArgs
public class ColorResolutionCommandDataEvent extends LeadEvent public ref class ColorResolutionCommandDataEventArgs : public System.EventArgs This example will convert an image from 24 to 1 bits/pixel saving the data into an external image manually
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 diskRasterImage 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 imageColorResolutionCommand 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 diskcodecs.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:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingPublic 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 diskDim 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 imageDim command As ColorResolutionCommand = New ColorResolutionCommand()command.BitsPerPixel = 1command.DitheringMethod = RasterDitheringMethod.FloydSteinAddHandler command.Data, AddressOf command_Data_destImage.Access()command.Run(srcImage)_destImage.Release()RemoveHandler command.Data, AddressOf command_Data' Save it to diskcodecs.Save(_destImage, destFileName, RasterImageFormat.Bmp, 4)_destImage.Dispose()' Clean UpsrcImage.Dispose()End SubPrivate _destImage As RasterImagePrivate _row As IntegerPrivate 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 SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
