VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Wpf.UI Namespace / WpfImageViewerBase Class / ImageDecodingSettings Property
Example



In This Topic
    ImageDecodingSettings Property (WpfImageViewerBase)
    In This Topic
    Gets or sets the decoding settings of this viewer.
    Syntax
    'Declaration
     
    <BrowsableAttribute(False)>
    Public Property ImageDecodingSettings As DecodingSettings
    [Browsable(false)]
    public DecodingSettings ImageDecodingSettings {get; set;}
    [Browsable(false)]
    public: __property DecodingSettings* get_ImageDecodingSettings();
    public: __property void set_ImageDecodingSettings( 
       DecodingSettings* value
    );
    [Browsable(false)]
    public:
    property DecodingSettings^ ImageDecodingSettings {
       DecodingSettings^ get();
       void set (    DecodingSettings^ value);
    }

    Property Value

    null - decoding settings of image (Vintasoft.Imaging.VintasoftImage.Vintasoft.Imaging.VintasoftImage.DecodingSettings) is used for decoding the image;
    not null - decoding settings of image viewer (Vintasoft.Imaging.UI.ImageViewerBase.ImageDecodingSettings) is used for decoding the image.
    Default value is null.
    Example
    This example illustrates how to enable or disable color management in image viewer.
    ''' <summary>
    ''' Enables the color management in image or thumbnail viewer.
    ''' </summary>
    ''' <param name="viewer">An image/thumbnail viewer.</param>
    ''' <param name="inputCmykProfile">The input CMYK profile.</param>
    ''' <param name="inputRgbProfile">The input RGB profile.</param>
    ''' <param name="outputRgbProfile">The output RGB profile.</param>
    Public Shared Sub EnableViewerColorManagement(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewerBase, inputCmykProfile As String, inputRgbProfile As String, outputRgbProfile As String)
        ' if all profiles are empty
        If String.IsNullOrEmpty(inputCmykProfile) AndAlso String.IsNullOrEmpty(inputRgbProfile) AndAlso String.IsNullOrEmpty(outputRgbProfile) Then
            Return
        End If
                
        ' get current image decoding settings from the viewer
        Dim decodingImageSettings As Vintasoft.Imaging.Codecs.Decoders.DecodingSettings = viewer.ImageDecodingSettings
        ' if viewer does not have image decoding settings
        If decodingImageSettings Is Nothing Then
            ' create new image decoding settings
            decodingImageSettings = New Vintasoft.Imaging.Codecs.Decoders.DecodingSettings()
        End If
                
        ' init the image decoding settings
        InitDecodingSettings(decodingImageSettings, inputCmykProfile, inputRgbProfile, outputRgbProfile)
                
        ' set decoding settings to the viewer
        viewer.ImageDecodingSettings = decodingImageSettings
        ' reload images in viewer
        ReloadViewerImages(viewer)
    End Sub
                
    ''' <summary>
    ''' Disables the color management decode settings.
    ''' </summary>
    ''' <param name="viewer">An image viewer.</param>
    Public Shared Sub DisableViewerColorManagement(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewerBase)
        ' get decoding settings from image/thumbnail viewer
        Dim imageDecodingSettings As Vintasoft.Imaging.Codecs.Decoders.DecodingSettings = viewer.ImageDecodingSettings
        If imageDecodingSettings Is Nothing Then
            Return
        End If
                
        ' destroy the image decoding settings
        DestroyColorManagementDecodeSettings(imageDecodingSettings.ColorManagement)
        imageDecodingSettings.ColorManagement = Nothing
                
        ' set decoding settings to the image/thumbnail viewer
        viewer.ImageDecodingSettings = imageDecodingSettings
        ' reload images in image/thumbnail viewer
        ReloadViewerImages(viewer)
    End Sub
                
    ''' <summary>
    ''' Initializes the decoding settings.
    ''' </summary>
    ''' <param name="decodingSettings">Image decoding settings.</param>
    ''' <param name="inputCmykProfile">The input CMYK profile.</param>
    ''' <param name="inputRgbProfile">The input RGB profile.</param>
    ''' <param name="outputRgbProfile">The output RGB profile.</param>
    Private Shared Sub InitDecodingSettings(decodingSettings As Vintasoft.Imaging.Codecs.Decoders.DecodingSettings, inputCmykProfile As String, inputRgbProfile As String, outputRgbProfile As String)
        DestroyColorManagementDecodeSettings(decodingSettings.ColorManagement)
        decodingSettings.ColorManagement = Nothing
                
        decodingSettings.ColorManagement = New Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings()
                
        InitColorManagementDecodeSettings(decodingSettings.ColorManagement, inputCmykProfile, inputRgbProfile, outputRgbProfile)
    End Sub
                
    ''' <summary>
    ''' Destroys the color management decode settings.
    ''' </summary>
    ''' <param name="colorManagementDecodeSettings">Color management decode settings.</param>
    Private Shared Sub DestroyColorManagementDecodeSettings(colorManagementDecodeSettings As Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings)
        If colorManagementDecodeSettings IsNot Nothing Then
            ' if input CMYK profile is not empty
            If colorManagementDecodeSettings.InputCmykProfile IsNot Nothing Then
                ' remove input CMYK profile
                colorManagementDecodeSettings.InputCmykProfile.Dispose()
            End If
                
            ' if input RGB profile is not empty
            If colorManagementDecodeSettings.InputRgbProfile IsNot Nothing Then
                ' remove input RGB profile
                colorManagementDecodeSettings.InputRgbProfile.Dispose()
            End If
                
            ' if output RGB profile is not empty
            If colorManagementDecodeSettings.OutputRgbProfile IsNot Nothing Then
                ' remove output RGB profile
                colorManagementDecodeSettings.OutputRgbProfile.Dispose()
            End If
        End If
    End Sub
                
    ''' <summary>
    ''' Initializes the color management decode settings.
    ''' </summary>
    ''' <param name="colorManagementDecodeSettings">Color management decode settings.</param>
    ''' <param name="inputCmykProfile">The input CMYK profile.</param>
    ''' <param name="inputRgbProfile">The input RGB profile.</param>
    ''' <param name="outputRgbProfile">The output RGB profile.</param>
    Private Shared Sub InitColorManagementDecodeSettings(colorManagementDecodeSettings As Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings, inputCmykProfile As String, inputRgbProfile As String, outputRgbProfile As String)
        ' if input CMYK profile is not empty
        If Not String.IsNullOrEmpty(inputCmykProfile) Then
            ' set input CMYK profile
            colorManagementDecodeSettings.InputCmykProfile = New Vintasoft.Imaging.ColorManagement.Icc.IccProfile(inputCmykProfile)
        End If
        ' if input RGB profile is not empty
        If Not String.IsNullOrEmpty(inputRgbProfile) Then
            ' set input RGB profile
            colorManagementDecodeSettings.InputRgbProfile = New Vintasoft.Imaging.ColorManagement.Icc.IccProfile(inputRgbProfile)
        End If
        ' if output RGB profile is not empty
        If Not String.IsNullOrEmpty(outputRgbProfile) Then
            ' set output RGB profile
            colorManagementDecodeSettings.OutputRgbProfile = New Vintasoft.Imaging.ColorManagement.Icc.IccProfile(outputRgbProfile)
        End If
    End Sub
                
    ''' <summary>
    ''' Reloads the images in the specified image/thumbnail viewer.
    ''' </summary>
    ''' <param name="viewer">The image/thumbnail viewer.</param>
    Private Shared Sub ReloadViewerImages(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewerBase)
        Try
            ' get the image collection
            Dim images As Vintasoft.Imaging.ImageCollection = viewer.Images
            ' get the focused image
            Dim focusedIndex As Integer = viewer.FocusedIndex
            Dim focusedImage As Vintasoft.Imaging.VintasoftImage = Nothing
            If focusedIndex >= 0 AndAlso focusedIndex < images.Count Then
                focusedImage = images(focusedIndex)
                ' if focused image is not empty
                If focusedImage IsNot Nothing Then
                    ' reload image
                    focusedImage.Reload(True)
                End If
            End If
                
            ' for each image in collection
            For Each image As Vintasoft.Imaging.VintasoftImage In images
                ' if this is not focused image
                If image IsNot focusedImage Then
                    ' reload image
                    image.Reload(True)
                End If
            Next
        Catch ex As System.Exception
            ' show error message
            System.Windows.MessageBox.Show(ex.Message, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.[Error])
        End Try
    End Sub
    /// <summary>
    /// Enables the color management in image or thumbnail viewer.
    /// </summary>
    /// <param name="viewer">An image/thumbnail viewer.</param>
    /// <param name="inputCmykProfile">The input CMYK profile.</param>
    /// <param name="inputRgbProfile">The input RGB profile.</param>
    /// <param name="outputRgbProfile">The output RGB profile.</param>
    public static void EnableViewerColorManagement(
        Vintasoft.Imaging.Wpf.UI.WpfImageViewerBase viewer,
        string inputCmykProfile,
        string inputRgbProfile,
        string outputRgbProfile)
    {
        // if all profiles are empty
        if (string.IsNullOrEmpty(inputCmykProfile) &&
            string.IsNullOrEmpty(inputRgbProfile) &&
            string.IsNullOrEmpty(outputRgbProfile))
            return;
                
        // get current image decoding settings from the viewer
        Vintasoft.Imaging.Codecs.Decoders.DecodingSettings decodingImageSettings = viewer.ImageDecodingSettings;
        // if viewer does not have image decoding settings
        if (decodingImageSettings == null)
            // create new image decoding settings
            decodingImageSettings = new Vintasoft.Imaging.Codecs.Decoders.DecodingSettings();
                
        // init the image decoding settings
        InitDecodingSettings(decodingImageSettings, inputCmykProfile, inputRgbProfile, outputRgbProfile);
                
        // set decoding settings to the viewer
        viewer.ImageDecodingSettings = decodingImageSettings;
        // reload images in viewer
        ReloadViewerImages(viewer);
    }
                
    /// <summary>
    /// Disables the color management decode settings.
    /// </summary>
    /// <param name="viewer">An image viewer.</param>
    public static void DisableViewerColorManagement(Vintasoft.Imaging.Wpf.UI.WpfImageViewerBase viewer)
    {
        // get decoding settings from image/thumbnail viewer
        Vintasoft.Imaging.Codecs.Decoders.DecodingSettings imageDecodingSettings = viewer.ImageDecodingSettings;
        if (imageDecodingSettings == null)
            return;
                
        // destroy the image decoding settings
        DestroyColorManagementDecodeSettings(imageDecodingSettings.ColorManagement);
        imageDecodingSettings.ColorManagement = null;
                
        // set decoding settings to the image/thumbnail viewer
        viewer.ImageDecodingSettings = imageDecodingSettings;
        // reload images in image/thumbnail viewer
        ReloadViewerImages(viewer);
    }
                
    /// <summary>
    /// Initializes the decoding settings.
    /// </summary>
    /// <param name="decodingSettings">Image decoding settings.</param>
    /// <param name="inputCmykProfile">The input CMYK profile.</param>
    /// <param name="inputRgbProfile">The input RGB profile.</param>
    /// <param name="outputRgbProfile">The output RGB profile.</param>
    static void InitDecodingSettings(
        Vintasoft.Imaging.Codecs.Decoders.DecodingSettings decodingSettings,
        string inputCmykProfile,
        string inputRgbProfile,
        string outputRgbProfile)
    {
        DestroyColorManagementDecodeSettings(decodingSettings.ColorManagement);
        decodingSettings.ColorManagement = null;
                
        decodingSettings.ColorManagement = new Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings();
                
        InitColorManagementDecodeSettings(decodingSettings.ColorManagement, inputCmykProfile, inputRgbProfile, outputRgbProfile);
    }
                
    /// <summary>
    /// Destroys the color management decode settings.
    /// </summary>
    /// <param name="colorManagementDecodeSettings">Color management decode settings.</param>
    static void DestroyColorManagementDecodeSettings(
        Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings colorManagementDecodeSettings)
    {
        if (colorManagementDecodeSettings != null)
        {
            // if input CMYK profile is not empty
            if (colorManagementDecodeSettings.InputCmykProfile != null)
            {
                // remove input CMYK profile
                colorManagementDecodeSettings.InputCmykProfile.Dispose();
            }
                
            // if input RGB profile is not empty
            if (colorManagementDecodeSettings.InputRgbProfile != null)
            {
                // remove input RGB profile
                colorManagementDecodeSettings.InputRgbProfile.Dispose();
            }
                
            // if output RGB profile is not empty
            if (colorManagementDecodeSettings.OutputRgbProfile != null)
            {
                // remove output RGB profile
                colorManagementDecodeSettings.OutputRgbProfile.Dispose();
            }
        }
    }
                
    /// <summary>
    /// Initializes the color management decode settings.
    /// </summary>
    /// <param name="colorManagementDecodeSettings">Color management decode settings.</param>
    /// <param name="inputCmykProfile">The input CMYK profile.</param>
    /// <param name="inputRgbProfile">The input RGB profile.</param>
    /// <param name="outputRgbProfile">The output RGB profile.</param>
    static void InitColorManagementDecodeSettings(
        Vintasoft.Imaging.ColorManagement.ColorManagementDecodeSettings colorManagementDecodeSettings,
        string inputCmykProfile,
        string inputRgbProfile,
        string outputRgbProfile)
    {
        // if input CMYK profile is not empty
        if (!string.IsNullOrEmpty(inputCmykProfile))
        {
            // set input CMYK profile
            colorManagementDecodeSettings.InputCmykProfile =
                new Vintasoft.Imaging.ColorManagement.Icc.IccProfile(inputCmykProfile);
        }
        // if input RGB profile is not empty
        if (!string.IsNullOrEmpty(inputRgbProfile))
        {
            // set input RGB profile
            colorManagementDecodeSettings.InputRgbProfile =
                new Vintasoft.Imaging.ColorManagement.Icc.IccProfile(inputRgbProfile);
        }
        // if output RGB profile is not empty
        if (!string.IsNullOrEmpty(outputRgbProfile))
        {
            // set output RGB profile
            colorManagementDecodeSettings.OutputRgbProfile =
                new Vintasoft.Imaging.ColorManagement.Icc.IccProfile(outputRgbProfile);
        }
    }
                
    /// <summary>
    /// Reloads the images in the specified image/thumbnail viewer.
    /// </summary>
    /// <param name="viewer">The image/thumbnail viewer.</param>
    static void ReloadViewerImages(Vintasoft.Imaging.Wpf.UI.WpfImageViewerBase viewer)
    {
        try
        {
            // get the image collection
            Vintasoft.Imaging.ImageCollection images = viewer.Images;
            // get the focused image
            int focusedIndex = viewer.FocusedIndex;
            Vintasoft.Imaging.VintasoftImage focusedImage = null;
            if (focusedIndex >= 0 && focusedIndex < images.Count)
            {
                focusedImage = images[focusedIndex];
                // if focused image is not empty
                if (focusedImage != null)
                {
                    // reload image
                    focusedImage.Reload(true);
                }
            }
                
            // for each image in collection
            foreach (Vintasoft.Imaging.VintasoftImage image in images)
            {
                // if this is not focused image
                if (image != focusedImage)
                {
                    // reload image
                    image.Reload(true);
                }
            }
        }
        catch (System.Exception ex)
        {
            // show error message
            System.Windows.MessageBox.Show(ex.Message, "Error",
                System.Windows.MessageBoxButton.OK,
                System.Windows.MessageBoxImage.Error);
        }
    }
    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also