public static void Startup() Public Shared Sub Startup()
public:static void Startup();
This static method must be called before calling any other ColorConversion methods. This usually occurs at the start of your application.
This example will convert an image to CMYK color space and save the converted image to disk.
using Leadtools;using Leadtools.Codecs;using Leadtools.ColorConversion;public void StartupExample(){// Initialize the RasterCodecs classRasterCodecs codecs = new RasterCodecs();// StartUp the ColorConversion.RasterColorConverterEngine.Startup();// The input file namestring inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp");// load the input image as Bgr.RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);// Image buffer arraybyte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height];bgrImage.Access();// get image bufferfor (int i = 0; i < bgrImage.Height; i++)bgrImage.GetRow(i, bgrBuffer, i * bgrImage.BytesPerLine, bgrImage.BytesPerLine);bgrImage.Release();// Initialize a new Converter objectRasterColorConverterEngine converter = new RasterColorConverterEngine();byte[] cmykBuffer = new byte[bgrImage.Height * bgrImage.Width * 4];try{// Start the color conversionconverter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, null);// convert the image bufferconverter.Convert(bgrBuffer, // input buffer0, // offset from the beginning of the source buffercmykBuffer, // output buffer0, // offset from the beginning of the destination bufferbgrImage.Width, // pixels widthbgrImage.Height, // pixels heightbgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)),0); // 0 bytes align// stop the conversionconverter.Stop();// Initialize an image to hold the converted buffer.RasterImage cmykImage = new RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);// Start the color conversionconverter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, null);// convert the image bufferconverter.ConvertToImage(cmykBuffer, // converted buffer0, // offset from the beginning of the source buffercmykImage, // image to be savebgrImage.Width, // pixels widthbgrImage.Height, // pixels height0, // 0 bytes alignbgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)));// stop the conversionconverter.Stop();// the output File Name.string outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "ResultImage.bmp");// Save the result image.codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24);// dispose of the used imagesbgrImage.Dispose();cmykImage.Dispose();}catch (Exception ex){MessageBox.Show(ex.ToString());}// Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown();}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ColorConversionPublic Sub StartupExample()' Initialize the RasterCodecs classDim codecs As New RasterCodecs()' StartUp the ColorConversion.RasterColorConverterEngine.Startup()' The input file nameDim inputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")' load the input image as Bgr.Dim bgrImage As RasterImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)' Image buffer array'Dim bgrBuffer As Byte() = New Byte(bgrImage.BytesPerLine * bgrImage.Height - 1) {}Dim bgrBuffer(bgrImage.BytesPerLine * bgrImage.Height) As Byte' get image bufferbgrImage.Access()For i As Integer = 0 To bgrImage.Height - 1bgrImage.GetRow(i, bgrBuffer, (i * bgrImage.BytesPerLine), bgrImage.BytesPerLine)NextbgrImage.Release()' Initialize a new Converter objectDim converter As New RasterColorConverterEngine()' Cmyk buffer arrayDim cmykBuffer As Byte() = New Byte(bgrImage.Height * bgrImage.Width * 4 - 1) {}Try' Start the color conversionconverter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, Nothing)' convert the image bufferconverter.Convert(bgrBuffer,0,cmykBuffer,0,bgrImage.Width,bgrImage.Height,CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))),0)' stop the conversionconverter.[Stop]()' Initialize an image to hold the converted buffer.Dim cmykImage As New RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft,Nothing, IntPtr.Zero, 0)' Start the color conversionconverter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, Nothing)converter.ConvertToImage(cmykBuffer,0,cmykImage,bgrImage.Width,bgrImage.Height,0,CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))))' stop the conversionconverter.Stop()' the output File Name.Dim outputFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "ResultImage.bmp")' Save the result image.codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24)' dispose of the used imagesbgrImage.Dispose()cmykImage.Dispose()Catch ex As ExceptionMessageBox.Show(ex.ToString())End Try' Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown()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
