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




parameters
A ConversionParameters object that describes the conversion properties to be set.
Sets new conversion parameters.

Syntax

Visual Basic (Declaration) 
Public Sub SetParameters( _
   ByVal parameters As ConversionParameters _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterColorConverter
Dim parameters As ConversionParameters
 
instance.SetParameters(parameters)
C# 
public void SetParameters( 
   ConversionParameters parameters
)
Managed Extensions for C++ 
public: void SetParameters( 
   ConversionParameters* parameters
) 
C++/CLI 
public:
void SetParameters( 
   ConversionParameters^ parameters
) 

Parameters

parameters
A ConversionParameters object that describes the conversion properties to be set.

Example

This example will convert a cmyk buffer to rgb buffer.

Visual BasicCopy Code
Public Function GetCmykBufferFromImage(ByVal bgrImage As RasterImage) As Byte()
    ' StartUp the ColorConversion.
    RasterColorConverter.Startup()
    ' Image buffer array
    Dim bgrBuffer(bgrImage.BytesPerLine * bgrImage.Height) As Byte

    ' get image buffer
    Dim i As Integer
    For i = 0 To bgrImage.Height - 1
        bgrImage.GetRow(i, bgrBuffer, (i * bgrImage.BytesPerLine), bgrImage.BytesPerLine)
    Next i

    ' Initialize a new Converter object
    Dim converter As New RasterColorConverter()

    Dim cmykBuffer(bgrImage.Height * bgrImage.Width * 4) As Byte

    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()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    RasterColorConverter.Shutdown()

    Return cmykBuffer
End Function

Public Function GetImageFromCmykBuffer(ByVal cmykBuffer As Byte(), ByVal width As Integer, ByVal height As Integer) As RasterImage
    ' StartUp the ColorConversion.
    RasterColorConverter.Startup()

    ' Initialize a new Converter object
    Dim Converter As New RasterColorConverter()

    ' Initialize an image to hold the converted buffer.
    Dim cmykImage As RasterImage = Nothing
    Try
        cmykImage = New RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)

        ' Start the color conversion
        Converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, Nothing)

        ' convert the image buffer
        Converter.ConvertToImage(cmykBuffer, _
           0, _
           cmykImage, _
           width, _
           height, _
           0, _
           CInt(cmykImage.BytesPerLine - (cmykImage.Width * (cmykImage.BitsPerPixel / 8))))

        ' stop the conversion
        Converter.Stop()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    ' Shutdown the ColorConversion.
    RasterColorConverter.Shutdown()
    Return cmykImage
End Function


Public Sub SetParametersExample()
    ' StartUp the RasterCodecs.
    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)

    Dim width As Integer = bgrImage.Width
    Dim height As Integer = bgrImage.Height
    Dim cmykBuffer() As Byte = GetCmykBufferFromImage(bgrImage)

    ' Initialize the Rgb buffer array
    Dim rgbBuffer(CInt(cmykBuffer.Length - cmykBuffer.Length / 4)) As Byte

    ' Initialize a new Converter object
    Dim converter As New RasterColorConverter

    ' Initialize a new ConversionParameters class object.
    Dim convParams As ConversionParameters = New ConversionParameters

    ' we want to use the built in LEAD ICC conversion method and built in conversion
    convParams.Method = ConversionMethodFlags.UseBuiltIn Or ConversionMethodFlags.UseIcc

    ' set the active conversion method
    convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn

    ' Initialize WhitePoint property class.
    convParams.WhitePoint = New ConversionWhitePoint

    ' Set WhitePoint property.
    Dim whitePoint As ConversionWhitePoint
    whitePoint.WhitePoint = ConversionWhitePointType.D50
    convParams.WhitePoint = whitePoint

    ' Initialize CmykParameters property class.
    convParams.CmykParameters = New ConversionCmykParameters

    ' Set GcrLevel property.
    Dim cmykParameters As ConversionCmykParameters
    cmykParameters.GcrLevel = 150
    convParams.CmykParameters = cmykParameters

    Try
        ' Initialize the ColorConversion
        converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Rgb, convParams)

        ' convert the Cmyk buffer to Rgb buffer using Built-in conversion.
        converter.Convert(cmykBuffer, _
           0, _
           rgbBuffer, _
           0, _
           width, _
           height, _
           0, _
           CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))))

        ' Change the active method for conversion
        convParams.Method = ConversionMethodFlags.ChangeActiveMethod Or ConversionMethodFlags.ChangeCmyk

        ' Switch to ICC conversion method
        convParams.ActiveMethod = ConversionMethodFlags.UseIcc

        ' Set Mask property.
        cmykParameters.Mask = ConversionCmykMask.Gcr

        ' Set GcrLevel property.
        cmykParameters.GcrLevel = 175
        convParams.CmykParameters = cmykParameters

        ' Update the conversion parameters
        converter.SetParameters(convParams)

        ' convert the image buffer
        converter.Convert(cmykBuffer, _
        0, _
        rgbBuffer, _
        0, _
        width, _
        height, _
        0, _
        CInt(bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))))

        ' Stop the ColorConversion
        converter.Stop()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
        rgbBuffer = Nothing
    End Try

    ' the output File Name.
    Dim outputFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ResultImage.bmp"

    ' Save the converted Image
    Dim cmykImage As RasterImage = GetImageFromCmykBuffer(cmykBuffer, width, height)
    codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24)

    ' Shutdown the ColorConversion.
    RasterColorConverter.Shutdown()

    ' Shutdown the RasterCodecs
    RasterCodecs.Shutdown()
End Sub
C#Copy Code
public byte[] GetCmykBufferFromImage(RasterImage bgrImage) 

   // StartUp the ColorConversion. 
   RasterColorConverter.Startup(); 
   // 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(); 
   } 
   catch (Exception ex) 
   { 
      MessageBox.Show(ex.Message); 
   } 
 
   RasterColorConverter.Shutdown(); 
 
   return cmykBuffer; 

 
public RasterImage GetImageFromCmykBuffer(byte[] cmykBuffer, int width, int height) 

   // StartUp the ColorConversion. 
   RasterColorConverter.Startup(); 
 
   // Initialize a new Converter object 
   RasterColorConverter converter = new RasterColorConverter(); 
 
   // Initialize an image to hold the converted buffer. 
   RasterImage cmykImage = null; 
   try 
   { 
      cmykImage = new RasterImage(RasterMemoryFlags.Conventional, width, 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 
         width,   // pixels width 
         height,  // pixels height 
         0,                // 0 bytes align 
         cmykImage.BytesPerLine - (cmykImage.Width * (cmykImage.BitsPerPixel / 8))); 
 
      // stop the conversion 
      converter.Stop(); 
   } 
   catch (Exception ex) 
   { 
      MessageBox.Show(ex.Message); 
   } 
   // Shutdown the ColorConversion. 
   RasterColorConverter.Shutdown(); 
   return cmykImage; 

 
 
public void SetParametersExample() 

   // Initialize the RasterCodecs 
   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); 
 
   int width = bgrImage.Width; 
   int height = bgrImage.Height; 
   byte[] cmykBuffer = GetCmykBufferFromImage(bgrImage); 
 
   // Initialize the Rgb buffer array 
   byte[] rgbBuffer = new byte[cmykBuffer.Length - cmykBuffer.Length / 4]; 
 
   // Initialize a new Converter object 
   RasterColorConverter converter = new RasterColorConverter(); 
 
   // Initialize a new ConversionParameters class object. 
   ConversionParameters convParams = new ConversionParameters(); 
 
   // we want to use the built in LEAD ICC conversion method and built in conversion 
   convParams.Method = ConversionMethodFlags.UseBuiltIn | ConversionMethodFlags.UseIcc; 
 
   // set the active conversion method 
   convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn; 
 
   // Initialize WhitePoint property class. 
   convParams.WhitePoint = new ConversionWhitePoint(); 
 
   // Set WhitePoint property. 
   ConversionWhitePoint whitePoint = new ConversionWhitePoint(); 
   whitePoint.WhitePoint = ConversionWhitePointType.D50; 
   convParams.WhitePoint = whitePoint; 
 
   // Initialize CmykParameters property class. 
   convParams.CmykParameters = new ConversionCmykParameters(); 
 
   // Set GcrLevel property. 
   ConversionCmykParameters cmykParameters = new ConversionCmykParameters(); 
   cmykParameters.GcrLevel = 150; 
   convParams.CmykParameters = cmykParameters; 
 
   try 
   { 
      // Initialize the ColorConversion 
      converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Rgb, convParams); 
 
      // convert the Cmyk buffer to Rgb buffer using Built-in conversion. 
      converter.Convert(cmykBuffer, 
         0, 
         rgbBuffer, 
         0, 
         width, 
         height, 
         0, 
         bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))); 
 
      // Change the active method for conversion 
      convParams.Method = ConversionMethodFlags.ChangeActiveMethod | ConversionMethodFlags.ChangeCmyk; 
 
      // Switch to ICC conversion method 
      convParams.ActiveMethod = ConversionMethodFlags.UseIcc; 
 
      // Set Mask property. 
      cmykParameters.Mask = ConversionCmykMask.Gcr; 
 
      // Set GcrLevel property. 
      cmykParameters.GcrLevel = 175; 
      convParams.CmykParameters = cmykParameters; 
 
      // Update the conversion parameters 
      converter.SetParameters(convParams); 
 
      // convert the image buffer  
      converter.Convert(cmykBuffer, 0, rgbBuffer, 0, width, height, 0, 0); 
 
      // Stop the ColorConversion 
      converter.Stop(); 
   } 
   catch(Exception ex) 
   { 
      MessageBox.Show(ex.Message); 
      rgbBuffer = null; 
   } 
 
   // the output File Name. 
   string outputFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\ResultImage.bmp"; 
 
   // Save the converted Image 
   RasterImage cmykImage = GetImageFromCmykBuffer(cmykBuffer, width, height); 
   codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24); 
 
   // Shutdown the ColorConversion. 
   RasterColorConverter.Shutdown(); 
 
   // Shutdown the RasterColor 
   RasterCodecs.Shutdown(); 
}

Remarks

The parameters parameter should not be null(Nothing). If it is, this method will fail.

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