Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.11.2
|
Leadtools.ColorConversion Namespace > RasterColorConverterEngine Class : Startup Method |
public static void Startup()
'Declaration Public Shared Sub Startup()
'Usage RasterColorConverterEngine.Startup()
public: static void Startup();
This example will convert an image to CMYK color space and save the converted image to disk.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ColorConversion <TestMethod()> _ Public Sub StartupExample() ' Initialize the RasterCodecs class Dim codecs As New RasterCodecs() ' StartUp the ColorConversion. RasterColorConverterEngine.Startup() ' The input file name Dim 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 buffer For i As Integer = 0 To bgrImage.Height - 1 bgrImage.GetRow(i, bgrBuffer, (i * bgrImage.BytesPerLine), bgrImage.BytesPerLine) Next ' Initialize a new Converter object Dim converter As New RasterColorConverterEngine() ' Cmyk buffer array Dim cmykBuffer As Byte() = New Byte(bgrImage.Height * bgrImage.Width * 4 - 1) {} Try ' Start the color conversion converter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, Nothing) ' convert the image buffer converter.Convert(bgrBuffer, _ 0, _ cmykBuffer, _ 0, _ bgrImage.Width, _ bgrImage.Height, _ CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))), _ 0) ' stop the conversion converter.[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 conversion converter.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 conversion converter.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 images bgrImage.Dispose() cmykImage.Dispose() Catch ex As Exception MessageBox.Show(ex.ToString()) End Try ' Shutdown the ColorConversion. RasterColorConverterEngine.Shutdown() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.ColorConversion; [TestMethod] public void StartupExample() { // Initialize the RasterCodecs class RasterCodecs codecs = new RasterCodecs(); // StartUp the ColorConversion. RasterColorConverterEngine.Startup(); // The input file name string 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 array byte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height]; // get image buffer for (int i = 0; i < bgrImage.Height; i++) bgrImage.GetRow(i, bgrBuffer, i * bgrImage.BytesPerLine, bgrImage.BytesPerLine); // Initialize a new Converter object RasterColorConverterEngine converter = new RasterColorConverterEngine(); byte[] cmykBuffer = new byte[bgrImage.Height * bgrImage.Width * 4]; try { // Start the color conversion converter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, null); // convert the image buffer converter.Convert(bgrBuffer, // input buffer 0, // offset from the begining of the source buffer cmykBuffer, // output buffer 0, // offset from the begining of the destination buffer bgrImage.Width, // pixels width bgrImage.Height, // pixels height bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)), 0); // 0 bytes align // stop the conversion converter.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 conversion converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, null); // convert the image buffer converter.ConvertToImage(cmykBuffer, // converted buffer 0, // offset from the begining of the source buffer cmykImage, // image to be save bgrImage.Width, // pixels width bgrImage.Height, // pixels height 0, // 0 bytes align bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))); // stop the conversion converter.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 images bgrImage.Dispose(); cmykImage.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } // Shutdown the ColorConversion. RasterColorConverterEngine.Shutdown(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools; using Leadtools.Codecs; using Leadtools.ColorConversion; public void StartupExample() { // Initialize the RasterCodecs class RasterCodecs codecs = new RasterCodecs(); // StartUp the ColorConversion. RasterColorConverterEngine.Startup(); // The input file name string inputFileName = LeadtoolsExamples.Common.ImagesPath.Path + "image1.cmp"; // load the input image as Bgr. RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1); // Image buffer array byte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height]; // get image buffer for (int i = 0; i < bgrImage.Height; i++) bgrImage.GetRow(i, bgrBuffer, i * bgrImage.BytesPerLine, bgrImage.BytesPerLine); byte[] cmykBuffer = new byte[bgrImage.Height * bgrImage.Width * 4]; try { // convert the image buffer RasterColorConverterEngine.ConvertDirect(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, bgrBuffer, // input buffer 0, // offset from the begining of the source buffer cmykBuffer, // output buffer 0, // offset from the begining of the destination buffer bgrImage.Width, // pixels width bgrImage.Height, // pixels height bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)), 0); // 0 bytes align // Initialize an image to hold the converted buffer. RasterImage cmykImage = new RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, null, 0); // convert the image buffer RasterColorConverterEngine.ConvertDirectToImage (ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, cmykBuffer, // converted buffer 0, // offset from the begining of the source buffer cmykImage, // image to be save bgrImage.Width, // pixels width bgrImage.Height, // pixels height 0, // 0 bytes align bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))); // the output File Name. string outputFileName = LeadtoolsExamples.Common.ImagesPath.Path + "ResultImage.bmp"; // Save the result image. codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24); // dispose of the used images bgrImage.Dispose(); cmykImage.Dispose(); } catch (Exception) { } // Shutdown the ColorConversion. RasterColorConverterEngine.Shutdown(); }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ColorConversion <TestMethod> _ Public Sub StartupExample() ' Initialize the RasterCodecs class Dim codecs As RasterCodecs = New RasterCodecs() ' StartUp the ColorConversion. RasterColorConverterEngine.Startup() ' The input file name Dim inputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "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){} ' get image buffer Dim i As Integer = 0 Do While i < bgrImage.Height bgrImage.GetRow(i, bgrBuffer, i * bgrImage.BytesPerLine, bgrImage.BytesPerLine) i += 1 Loop Dim cmykBuffer As Byte() = New Byte(bgrImage.Height * bgrImage.Width * 4 - 1){} Try ' convert the image buffer RasterColorConverterEngine.ConvertDirect(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, bgrBuffer, 0, cmykBuffer, 0, bgrImage.Width, bgrImage.Height, bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel _ / 8)), 0) ' 0 bytes align ' Initialize an image to hold the converted buffer. Dim cmykImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, Nothing, Nothing, 0) ' convert the image buffer RasterColorConverterEngine.ConvertDirectToImage (ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, cmykBuffer, 0, cmykImage, bgrImage.Width, bgrImage.Height, 0, bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))) ' the output File Name. Dim outputFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "ResultImage.bmp" ' Save the result image. codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24) ' dispose of the used images bgrImage.Dispose() cmykImage.Dispose() Catch e1 As Exception End Try ' Shutdown the ColorConversion. RasterColorConverterEngine.Shutdown() End Sub