←Select platform

ConvertImage(RasterImage,RasterImage) Method

Summary

Converts image data in a RasterImage based on its ICC profile and sets the output as a RasterImage.

Syntax

C#
C++/CLI
Python
public void ConvertImage( 
   RasterImage srcImage, 
   RasterImage dstImage 
) 
public:  
   static void ConvertImage( 
      RasterImage^ srcImage, 
      RasterImage^ dstImage 
   ) 
def ConvertImage(self,srcImage,dstImage): 

Parameters

srcImage

A RasterImage object holding the input data. The source RasterImage provides an ICC profile that is applied for this conversion.

dstImage

A RasterImage object that will hold the converted data.

Remarks

There are other conversion methods available in the LEADTOOLS Color Conversion toolkit, however, to get optimal conversion results use ConvertImage(RasterImage,RasterImage) or ConvertImage(RasterImage,RasterImage) as they rely on the embedded ICC profile of the source RasterImage. Here is a scenario where these two methods are invaluable:

  1. An image is loaded to a viewer.
  2. The image in the viewer displays colors that are visibly off from a reference image.
  3. To correct the colors, the source image is converted using the embedded ICC profile with one of these two methods.

srcImage and dstImage should be allocated and have the same width and height. Both images should be 24-bit.

The conversion engine should have already been started by calling Start. The input and output formats for the conversion engine should be BGR/RGB for predictable results. Other types of conversion (LAB, CMYK, etc) might have undesired results.

You can perform the conversion in-place (storing the output in the source bitmap) using ConvertImage(RasterImage).

Example

This example loads a source file containing an embedded ICC profile. The image data will be converted using the ConvertImage(RasterImage,RasterImage) method.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ColorConversion; 
 
 
       
public void ConvertImageToImageExample() 
{ 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      string inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "test_11800-Embedded-RGB.png"); 
 
      /* Load the original image */ 
      using (RasterImage srcImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)) 
      { 
         ConversionParameters conversionParameters = new ConversionParameters(); 
 
         /* Set the active method */ 
         conversionParameters.Method = ConversionMethodFlags.UseCustomIcc; 
         conversionParameters.ActiveMethod = ConversionMethodFlags.UseCustomIcc; 
 
         bool hasProfile = IccProfileExtended.ImageHasIccProfile(inputFileName, 1); 
         Debug.WriteLine("Profile present:\t" + hasProfile); 
 
         /* Read the profile from image on disk */ 
         IccProfileExtended icc = new IccProfileExtended(); 
         icc.ReadFromImage(inputFileName, 1); 
 
         /* Use the image profile as the input profile */ 
         conversionParameters.InputProfileData = icc.Data; 
 
         using (RasterImage dstImage = srcImage.Clone()) 
         using (RasterColorConverterEngine colorConverter = new RasterColorConverterEngine()) 
         { 
            // Convert the image 
            colorConverter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Bgr, conversionParameters); 
            colorConverter.ConvertImage(srcImage, dstImage); 
            colorConverter.Stop(); 
 
            string outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "out-ICCConverted.png"); 
            codecs.Save(dstImage, outputFileName, srcImage.OriginalFormat, srcImage.BitsPerPixel); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

Reference

ConvertImage(RasterImage)

RasterColorConverterEngine Class

RasterColorConverterEngine Members

Leadtools.ColorConversion Namespace

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.