VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.UI Namespace / ImageViewerBase Class / ImageDecodingSettings Property
Синтаксис Example Требования Смотрите также
В этом разделе
    ImageDecodingSettings Свойство (ImageViewerBase)
    В этом разделе
    Возвращает или устанавливает настройки декодирования этого просмотрщика.
    Синтаксис

    Property Value

    null - настройки декодирования изображения (VintasoftImage.DecodingSettings) используется для декодирования изображения;
    not null - настройки декодирования просмотрщика изображений (ImageDecodingSettings) используются для декодирования изображения.
    Значение по умолчанию: null.
    Пример

    Этот пример иллюстрирует, как включить или отключить управление цветом в просмотрщике изображений.

    
    ''' <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.UI.ImageViewerBase, 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 in image/thumbnail viewer.
    ''' </summary>
    ''' <param name="viewer">An image/thumbnail viewer.</param>
    Public Shared Sub DisableViewerColorManagement(viewer As Vintasoft.Imaging.UI.ImageViewerBase)
        ' 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.UI.ImageViewerBase)
        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.Forms.MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.[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.UI.ImageViewerBase 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 in image/thumbnail viewer.
    /// </summary>
    /// <param name="viewer">An image/thumbnail viewer.</param>
    public static void DisableViewerColorManagement(Vintasoft.Imaging.UI.ImageViewerBase 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.UI.ImageViewerBase 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.Forms.MessageBox.Show(ex.Message, "Error",
                System.Windows.Forms.MessageBoxButtons.OK,
                System.Windows.Forms.MessageBoxIcon.Error);
        }
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также