Leadtools.ColorConversion Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.5.7
Startup Method
See Also  Example
Leadtools.ColorConversion Namespace > RasterColorConverter Class : Startup Method




Initializes the required data to start the color conversion toolkit.

Syntax

Visual Basic (Declaration) 
Public Shared Sub Startup() 
Visual Basic (Usage)Copy Code
RasterColorConverter.Startup()
C# 
public static void Startup()
Managed Extensions for C++ 
public: static void Startup(); 
C++/CLI 
public:
static void Startup(); 

Example

This example will converts an image to Cmyk color space and save the converted image to disk.

Visual BasicCopy Code
Public Sub StartupExample()
    ' Initialize the RasterCodecs class
    RasterCodecs.Startup()
    Dim codecs As New RasterCodecs()

    ' StartUp the ColorConversion.
    RasterColorConverter.Startup()

    ' The input file name
    Dim inputFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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 RasterColorConverter()

    ' 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 = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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.
    RasterColorConverter.Shutdown()
    RasterCodecs.Shutdown()
End Sub
C#Copy Code
public void StartupExample() 

    // Initialize the RasterCodecs class  
    RasterCodecs.Startup(); 
    RasterCodecs codecs = new RasterCodecs(); 
 
    // StartUp the ColorConversion.  
    RasterColorConverter.Startup(); 
 
    // The input file name  
    string inputFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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  
    RasterColorConverter converter = new RasterColorConverter(); 
 
    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 = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\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.  
    RasterColorConverter.Shutdown(); 
    RasterCodecs.Shutdown();  
}

Remarks

This static method must be called before calling any other ColorConversion methods. This usually occurs at the start of your application.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also