←Select platform

Method Property

Summary
Gets or sets a value indicating the conversion method or the property to be changed.
Syntax
C#
C++/CLI
Python
public ConversionMethodFlags Method { get; set; } 
public: 
property ConversionMethodFlags Method { 
   ConversionMethodFlags get(); 
   void set (    ConversionMethodFlags ); 
} 
Method # get and set (ConversionParameters) 

Property Value

This property works in one of two ways:

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ColorConversion; 
 
using Leadtools.ImageProcessing; 
 
public string outputFile = Path.Combine(LEAD_VARS.ImagesDir, "ColorConversion", "WhitePoint.tif"); 
 
public void WhitePointPropertyExample() 
{ 
   // StartUp the ColorConversion. 
   RasterColorConverterEngine.Startup(); 
 
   // Input file name 
   string inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
 
   // Load the input image as Rgb 
   using (RasterCodecs codecs = new RasterCodecs()) 
   using (RasterImage rgbImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Rgb, 1, 1)) 
   { 
      // Get image buffer 
      byte[] rgbBuffer = new byte[rgbImage.BytesPerLine * rgbImage.Height]; 
      rgbImage.Access(); 
      for (int i = 0; i < rgbImage.Height; i++) 
         rgbImage.GetRow(i, rgbBuffer, i * rgbImage.BytesPerLine, rgbImage.BytesPerLine); 
      rgbImage.Release(); 
 
      // Initialize the Cmyk buffer array 
      byte[] cmykBuffer = new byte[rgbImage.Height * rgbImage.Width * 4]; 
 
      using (RasterColorConverterEngine colorConverterEngine = new RasterColorConverterEngine()) 
      { 
         // Conversion parameters 
         ConversionParameters convParams = new ConversionParameters(); 
         convParams.Method = ConversionMethodFlags.UseBuiltIn; 
         convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn; 
         convParams.Quantization = 8; 
         // WhitePoint 
         ConversionWhitePoint whitePoint = ConversionWhitePoint.Empty; 
         whitePoint.WhitePoint = ConversionWhitePointType.D50; 
         whitePoint.XWhite = 0; 
         whitePoint.YWhite = 0; 
         convParams.WhitePoint = whitePoint; 
         // CMYK 
         ConversionCmykParameters cmykParameters = new ConversionCmykParameters(); 
         cmykParameters.GcrLevel = 150; 
         convParams.CmykParameters = cmykParameters; 
 
         // Convert RGB to CMYK with above parameters 
         colorConverterEngine.Start(ConversionColorFormat.Rgb, ConversionColorFormat.Cmyk, convParams); 
         colorConverterEngine.Convert(rgbBuffer, // Source buffer 
             0, // Offset to the beginning of source buffer 
             cmykBuffer, // Destination buffer 
             0, // Offset to the beginning of destination buffer 
             rgbImage.Width, // Pixels width 
             rgbImage.Height, // Pixels height 
             rgbImage.BytesPerLine - (rgbImage.Width * (rgbImage.BitsPerPixel / 8)), // Scanline alignment for source buffer 
             0); // Scanline alignment for destination buffer 
         colorConverterEngine.Stop(); 
 
         // Save CMYK Image 
         // Split CMYK buffer to separate C, M, Y, and K planes 
         byte[] cBuffer = new byte[cmykBuffer.Length / 4]; 
         byte[] mBuffer = new byte[cmykBuffer.Length / 4]; 
         byte[] yBuffer = new byte[cmykBuffer.Length / 4]; 
         byte[] kBuffer = new byte[cmykBuffer.Length / 4]; 
         int index, cIndex, mIndex, yIndex, kIndex; 
         index = cIndex = mIndex = yIndex = kIndex = 0; 
         foreach (byte cmykByte in cmykBuffer) 
         { 
            switch (++index % 4) 
            { 
               case 0: 
                  kBuffer[kIndex++] = cmykByte; 
                  break; 
               case 1: 
                  cBuffer[cIndex++] = cmykByte; 
                  break; 
               case 2: 
                  mBuffer[mIndex++] = cmykByte; 
                  break; 
               case 3: 
                  yBuffer[yIndex++] = cmykByte; 
                  break; 
            } 
         } 
         // Combine planes into a single RasterImage with a page for each plane 
         using (RasterImage cPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, cBuffer, cBuffer.Length)) 
         using (RasterImage mPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, mBuffer, mBuffer.Length)) 
         using (RasterImage yPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, yBuffer, yBuffer.Length)) 
         using (RasterImage kPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, kBuffer, yBuffer.Length)) 
         { 
            cPlane.AddPage(mPlane); 
            cPlane.AddPage(yPlane); 
            cPlane.AddPage(kPlane); 
            // Save the 4 page CMYK plances Raster Image as a CMYK Image 
            codecs.SaveCmykPlanes(cPlane, outputFile, RasterImageFormat.TifCmyk, 0, 0, CodecsSavePageMode.Overwrite); 
         } 
      } 
   } 
 
   // Shutdown the ColorConversion. 
   RasterColorConverterEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.10.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ColorConversion Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.