VintaSoft Imaging .NET SDK 15.0: Documentation for .NET developer
In This Topic
    How to add ICC-profile to a JPEG image?
    In This Topic
    Here is C#/VB.NET code that shows how to add ICC-profile to a JPEG image using PageMetadata class:
    /// <summary>
    /// Adds ICC profile to the metadata of image page.
    /// </summary>
    /// <param name="imageFilePath">The image to which the ICC profile must be added.</param>
    /// <param name="outputImageFilePath">The result image with added ICC profile.</param>
    /// <param name="iccProfilePath">ICC profile file path.</param>
    public void AddIccProfileToPageMetadata(string imageFilePath, string outputImageFilePath, string iccProfilePath)
    {
        // open an image file
        using (Vintasoft.Imaging.VintasoftImage image = new Vintasoft.Imaging.VintasoftImage(imageFilePath))
        {
            // get ICC profile data
            byte[] iccProfileData = System.IO.File.ReadAllBytes(iccProfilePath);
            // add ICC profile to the metadata of image page
            AddIccProfileToPageMetadata(image, iccProfileData);
            // save the image
            image.Save(outputImageFilePath);
        }
    }
    
    /// <summary>
    /// Adds ICC profile to the metadata of image page.
    /// </summary>
    /// <param name="image">The image to which the ICC profile must be added.</param>
    /// <param name="iccProfileData">ICC profile data.</param>
    /// <exception cref="System.ArgumentException">Thrown if image page does not have metadata.</exception>
    public void AddIccProfileToPageMetadata(Vintasoft.Imaging.VintasoftImage image, byte[] iccProfileData)
    {
        // get metadata of image page
        Vintasoft.Imaging.Metadata.PageMetadata pageMetadata = image.Metadata.MetadataTree;
        // if image has metadata
        if (pageMetadata != null)
        {
            // add ICC profile data to metadata
            pageMetadata.AddIccProfile(iccProfileData);
        }
        else
        {
            throw new System.ArgumentException("The image does not have metadata.");
        }
    }
    
    ''' <summary>
    ''' Adds ICC profile to the metadata of image page.
    ''' </summary>
    ''' <param name="imageFilePath">The image to which the ICC profile must be added.</param>
    ''' <param name="outputImageFilePath">The result image with added ICC profile.</param>
    ''' <param name="iccProfilePath">ICC profile file path.</param>
    Public Sub AddIccProfileToPageMetadata(imageFilePath As String, outputImageFilePath As String, iccProfilePath As String)
        ' open an image file
        Using image As New Vintasoft.Imaging.VintasoftImage(imageFilePath)
            ' get ICC profile data
            Dim iccProfileData As Byte() = System.IO.File.ReadAllBytes(iccProfilePath)
            ' add ICC profile to the metadata of image page
            AddIccProfileToPageMetadata(image, iccProfileData)
            ' save the image
            image.Save(outputImageFilePath)
        End Using
    End Sub
    
    ''' <summary>
    ''' Adds ICC profile to the metadata of image page.
    ''' </summary>
    ''' <param name="image">The image to which the ICC profile must be added.</param>
    ''' <param name="iccProfileData">ICC profile data.</param>
    ''' <exception cref="System.ArgumentException">Thrown if image page does not have metadata.</exception>
    Public Sub AddIccProfileToPageMetadata(image As Vintasoft.Imaging.VintasoftImage, iccProfileData As Byte())
        ' get metadata of image page
        Dim pageMetadata As Vintasoft.Imaging.Metadata.PageMetadata = image.Metadata.MetadataTree
        ' if image has metadata
        If pageMetadata IsNot Nothing Then
            ' add ICC profile data to metadata
            pageMetadata.AddIccProfile(iccProfileData)
        Else
            Throw New System.ArgumentException("The image does not have metadata.")
        End If
    End Sub