VintaSoft Imaging .NET SDK 15.0: Documentation for .NET developer
In This Topic
    How to add ICC-profile to a JPEG2000 image?
    In This Topic
    Here is C#/VB.NET code that shows how to add ICC-profile to a JPEG2000 image using Jpeg2000Page class:
    /// <summary>
    /// Adds ICC-profile to a JPEG2000 image using Jpeg2000Page class.
    /// </summary>
    /// <param name="inputJpeg2000Filename">The name of input JPEG2000 file.</param>
    /// <param name="iccProfileFilename">The name of ICC-profile.</param>
    /// <param name="outputJpeg2000Filename">The name of output JPEG2000 file.</param>
    public static void AddIccProfileToJpeg2000Page(string inputJpeg2000Filename, string iccProfileFilename, string outputJpeg2000Filename)
    {
        // open an existing JPEG2000 file
        using (Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File jpeg2000File = 
            new Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File(inputJpeg2000Filename))
        {
            // get JPEG2000 page
            Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000Page jpeg2000Page = jpeg2000File.Page;
    
            // read bytes of ICC-profile from file
            byte[] iccProfile = System.IO.File.ReadAllBytes(iccProfileFilename);
            // add ICC-profile to a JPEG2000 page
            jpeg2000Page.IccProfile = iccProfile;
    
            // save JPEG2000 file to a new file
            jpeg2000File.Save(outputJpeg2000Filename);
        }
    }
    
    ''' <summary>
    ''' Adds ICC-profile to a JPEG2000 image using Jpeg2000Page class.
    ''' </summary>
    ''' <param name="inputJpeg2000Filename">The name of input JPEG2000 file.</param>
    ''' <param name="iccProfileFilename">The name of ICC-profile.</param>
    ''' <param name="outputJpeg2000Filename">The name of output JPEG2000 file.</param>
    Public Shared Sub AddIccProfileToJpeg2000Page(inputJpeg2000Filename As String, iccProfileFilename As String, outputJpeg2000Filename As String)
        '' open an existing JPEG2000 file
        Using jpeg2000File As Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File =
                New Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File(inputJpeg2000Filename)
            '' get JPEG2000 page
            Dim jpeg2000Page As Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000Page = jpeg2000File.Page
    
            '' read bytes of ICC-profile from file
            Dim iccProfile As Byte() = System.IO.File.ReadAllBytes(iccProfileFilename)
            '' add ICC-profile to a JPEG2000 page
            jpeg2000Page.IccProfile = iccProfile
    
            '' save JPEG2000 file to a New file
            jpeg2000File.Save(outputJpeg2000Filename)
        End Using
    End Sub
    


    Here is C#/VB.NET code that shows how to add ICC-profile to a JPEG2000 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