←Select platform

ConvertToImage(IntPtr,long,RasterImage,int,int,int,int) Method

Summary
Converts image data in a buffer from one color conversion model to RGB\BGR, and sets the output as RasterImage.
Syntax
C#
C++/CLI
Python
public void ConvertToImage( 
   IntPtr srcBuffer, 
   long srcBufferOffset, 
   RasterImage image, 
   int width, 
   int height, 
   int inAlign, 
   int outAlign 
) 
public: 
void ConvertToImage(  
   IntPtr srcBuffer, 
   int64 srcBufferOffset, 
   RasterImage^ image, 
   int width, 
   int height, 
   int inAlign, 
   int outAlign 
)  

Parameters

srcBuffer
A pointer to a buffer containing the input data.

srcBufferOffset
Offset to the first byte of the  srcBuffer data buffer.

image
An RasterImage object that will hold the converted data.

width
Width of pixels to be processed.

height
Height of pixels to be processed.

inAlign
Each scanline in the input buffer is a multiple of inAlign bytes.

outAlign
Each scan line in the output buffer is a multiple of outAlign bytes.

Remarks

The active conversion method is specified in the ConversionParameters object when calling the Start method. To change the active method, use the SetParameters method. Only methods supported by the initialized converter should be specified. The conversion is done if the BGR or RGB Color Space was specified as the destination format when the Start method was called. For more information about Alignment Parameters, refer to Alignment Parameters. To convert to the Yp41 type the input image width must be multiple of 8

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ColorConversion; 
 
 
public void WhitePointPropertyExample() 
{ 
   // 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 Rgb. 
   RasterImage rgbImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Rgb, 1, 1); 
 
   // Image buffer array 
   byte[] rgbBuffer = new byte[rgbImage.BytesPerLine * rgbImage.Height]; 
 
   rgbImage.Access(); 
   // get image buffer 
   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]; 
 
   // Initialize a new Converter object 
   RasterColorConverterEngine converter = new RasterColorConverterEngine(); 
 
   // Initialize a new ConversionParameters new class object. 
   ConversionParameters convParams = new ConversionParameters(); 
 
   // Initialize the WhitePoint property class. 
   ConversionWhitePoint whitePoint = ConversionWhitePoint.Empty; 
 
   // Set the WhitePoint property. 
   whitePoint.WhitePoint = ConversionWhitePointType.D50; 
 
   // Set the XWhite property. 
   whitePoint.XWhite = 0; 
 
   // Set the YWhite property. 
   whitePoint.YWhite = 0; 
   convParams.WhitePoint = whitePoint; 
 
   // Set the Quantization property. 
   convParams.Quantization = 8; 
 
   // Set the Method property. 
   convParams.Method = ConversionMethodFlags.UseBuiltIn; 
 
   // Set the ActiveMethod property. 
   convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn; 
 
   // Set GcrLevel property. 
   ConversionCmykParameters cmykParameters = new ConversionCmykParameters(); 
   cmykParameters.GcrLevel = 150; 
   convParams.CmykParameters = cmykParameters; 
 
   // Initialize an image to hold the converted buffer. 
   RasterImage cmykImage = null; 
   try 
   { 
      // Start the ColorConversion. 
      converter.Start(ConversionColorFormat.Rgb, ConversionColorFormat.Cmyk, convParams); 
 
      // Convert Rgb to CMYK. 
      converter.Convert( 
          rgbBuffer, 
          0, 
          cmykBuffer, 
          0, 
          rgbImage.Width, 
          rgbImage.Height, 
          rgbImage.BytesPerLine - (rgbImage.Width * (rgbImage.BitsPerPixel / 8)), 
          0); 
 
      // Stop the ColorConversion. 
      converter.Stop(); 
 
      // Initialize labImage. 
      cmykImage = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0); 
 
      // Start the color conversion 
      converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, convParams); 
 
      // convert the image buffer 
      converter.ConvertToImage(cmykBuffer, // converted buffer 
         0, // offset to the beginning of source buffer 
         cmykImage, // image to be save 
         rgbImage.Width, // pixels width 
         rgbImage.Height, // pixels height 
         0, // 0 bytes align 
         rgbImage.BytesPerLine - (rgbImage.Width * (rgbImage.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 the used images 
      rgbImage.Dispose(); 
      cmykImage.Dispose(); 
   } 
   catch (Exception ex) 
   { 
      Debug.WriteLine(ex.Message); 
   } 
   // Shutdown the ColorConversion. 
   RasterColorConverterEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.ColorConversion Assembly

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