ImageAttributes.SetOutputChannel 方法

定义

设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel.

重载

SetOutputChannel(ColorChannelFlag)

为默认类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category.

SetOutputChannel(ColorChannelFlag, ColorAdjustType)

为指定的类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category.

SetOutputChannel(ColorChannelFlag)

为默认类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category.

public:
 void SetOutputChannel(System::Drawing::Imaging::ColorChannelFlag flags);
public void SetOutputChannel (System.Drawing.Imaging.ColorChannelFlag flags);
member this.SetOutputChannel : System.Drawing.Imaging.ColorChannelFlag -> unit
Public Sub SetOutputChannel (flags As ColorChannelFlag)

参数

flags
ColorChannelFlag

ColorChannelFlag 的一个元素,指定输出通道。An element of ColorChannelFlag that specifies the output channel.

示例

下面的代码示例演示如何使用 SetOutputChannel 方法。The following code example demonstrates how to use the SetOutputChannel method. 若要运行此示例, 请将以下代码粘贴到 Windows 窗体中。To run this example, paste the following code into a Windows Form. 处理窗体的Paint事件并调用ShowOutputChannels, 传递ePaintEventArgsHandle the form's Paint event and call ShowOutputChannels, passing e as PaintEventArgs.

private void ShowOutputChannels(PaintEventArgs e)
{
    //Create a bitmap from a file.
    Bitmap bmp1 = new Bitmap("c:\\fakePhoto.jpg");

    // Create a new bitmap from the original, resizing it for this example.
    Bitmap bmp2 = new Bitmap(bmp1, new Size(80, 80));

    bmp1.Dispose();

    // Create an ImageAttributes object.
    ImageAttributes imgAttributes = new ImageAttributes();

    // Draw the image unaltered.
    e.Graphics.DrawImage(bmp2, 10, 10);

    // Draw the image, showing the intensity of the cyan channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelC,
        System.Drawing.Imaging.ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(bmp2, new Rectangle(100, 10, bmp2.Width, bmp2.Height),
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    // Draw the image, showing the intensity of the magenta channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelM,
        ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(bmp2, new Rectangle(10, 100, bmp2.Width, bmp2.Height),
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    // Draw the image, showing the intensity of the yellow channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelY,
        ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(bmp2, new Rectangle(100, 100, bmp2.Width, bmp2.Height), 0, 0,
        bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    // Draw the image, showing the intensity of the black channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelK,

        System.Drawing.Imaging.ColorAdjustType.Bitmap);
    e.Graphics.DrawImage(bmp2, new Rectangle(10, 190, bmp2.Width, bmp2.Height),
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    //Dispose of the bitmap.
    bmp2.Dispose();

}
Private Sub ShowOutputChannels(ByVal e As PaintEventArgs)

    'Create a bitmap from a file.
    Dim bmp1 As New Bitmap("c:\fakePhoto.jpg")

    ' Create a new bitmap from the original, resizing it for this example.
    Dim bmp2 As New Bitmap(bmp1, New Size(80, 80))

    bmp1.Dispose()

    ' Create an ImageAttributes object.
    Dim imgAttributes As New System.Drawing.Imaging.ImageAttributes()

    ' Draw the image unaltered.
    e.Graphics.DrawImage(bmp2, 10, 10)

    ' Draw the image, showing the intensity of the cyan channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelC, ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(100, 10, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    ' Draw the image, showing the intensity of the magenta channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelM, ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(10, 100, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    ' Draw the image, showing the intensity of the yellow channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelY, _
        ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(100, 100, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    ' Draw the image, showing the intensity of the black channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelK, _
        ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(10, 190, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    'Dispose of the bitmap.
    bmp2.Dispose()

End Sub

注解

可以使用SetOutputChannel方法将图像转换为 cmyk 颜色空间, 并检查其中一个 cmyk 颜色通道的浓度。You can use the SetOutputChannel method to convert an image to a CMYK color space and examine the intensities of one of the CMYK color channels. 例如, 假设您创建了一个ImageAttributes对象, 并将其位图输出通道ColorChannelC设置为。For example, suppose you create an ImageAttributes object and set its bitmap output channel to ColorChannelC. 如果将该ImageAttributes对象的路径传递DrawImage给方法, 则会计算每个像素的青色分量, 并且呈现图像中的每个像素都是灰色阴影, 指示其青色通道的强度。If you pass the path of that ImageAttributes object to the DrawImage method, the cyan component of each pixel is calculated, and each pixel in the rendered image is a shade of gray that indicates the intensity of its cyan channel. 同样, 您可以呈现指示洋红色、黄色和黑色通道强度的图像。Similarly, you can render images that indicate the intensities of the magenta, yellow, and black channels.

ImageAttributes对象维护五个调整类别的颜色和灰度设置: 默认值、位图、画笔、笔和文本。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如, 可以为默认类别指定输出通道, 并为位图类别指定不同的输出通道。For example, you can specify an output channel for the default category and a different output channel for the bitmap category.

默认颜色调整和灰度调整设置适用于没有自己的调整设置的所有类别。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如, 如果您从未为位图类别指定任何调整设置, 则默认设置将应用到位图类别。For example, if you never specify any adjustment settings for the bitmap category, the default settings apply to the bitmap category.

SetOutputChannel(ColorChannelFlag, ColorAdjustType)

为指定的类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category.

public:
 void SetOutputChannel(System::Drawing::Imaging::ColorChannelFlag flags, System::Drawing::Imaging::ColorAdjustType type);
public void SetOutputChannel (System.Drawing.Imaging.ColorChannelFlag flags, System.Drawing.Imaging.ColorAdjustType type);
member this.SetOutputChannel : System.Drawing.Imaging.ColorChannelFlag * System.Drawing.Imaging.ColorAdjustType -> unit
Public Sub SetOutputChannel (flags As ColorChannelFlag, type As ColorAdjustType)

参数

flags
ColorChannelFlag

ColorChannelFlag 的一个元素,指定输出通道。An element of ColorChannelFlag that specifies the output channel.

type
ColorAdjustType

ColorAdjustType 的一个元素,指定将设置输出通道的类别。An element of ColorAdjustType that specifies the category for which the output channel is set.

示例

下面的代码示例演示如何使用 SetOutputChannel 方法。The following code example demonstrates how to use the SetOutputChannel method. 若要运行此示例, 请将以下代码粘贴到 Windows 窗体中。To run this example, paste the following code into a Windows Form. 处理窗体的Paint事件并调用ShowOutputChannels, 传递ePaintEventArgsHandle the form's Paint event and call ShowOutputChannels, passing e as PaintEventArgs.

private void ShowOutputChannels(PaintEventArgs e)
{
    //Create a bitmap from a file.
    Bitmap bmp1 = new Bitmap("c:\\fakePhoto.jpg");

    // Create a new bitmap from the original, resizing it for this example.
    Bitmap bmp2 = new Bitmap(bmp1, new Size(80, 80));

    bmp1.Dispose();

    // Create an ImageAttributes object.
    ImageAttributes imgAttributes = new ImageAttributes();

    // Draw the image unaltered.
    e.Graphics.DrawImage(bmp2, 10, 10);

    // Draw the image, showing the intensity of the cyan channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelC,
        System.Drawing.Imaging.ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(bmp2, new Rectangle(100, 10, bmp2.Width, bmp2.Height),
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    // Draw the image, showing the intensity of the magenta channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelM,
        ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(bmp2, new Rectangle(10, 100, bmp2.Width, bmp2.Height),
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    // Draw the image, showing the intensity of the yellow channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelY,
        ColorAdjustType.Bitmap);

    e.Graphics.DrawImage(bmp2, new Rectangle(100, 100, bmp2.Width, bmp2.Height), 0, 0,
        bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    // Draw the image, showing the intensity of the black channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelK,

        System.Drawing.Imaging.ColorAdjustType.Bitmap);
    e.Graphics.DrawImage(bmp2, new Rectangle(10, 190, bmp2.Width, bmp2.Height),
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes);

    //Dispose of the bitmap.
    bmp2.Dispose();

}
Private Sub ShowOutputChannels(ByVal e As PaintEventArgs)

    'Create a bitmap from a file.
    Dim bmp1 As New Bitmap("c:\fakePhoto.jpg")

    ' Create a new bitmap from the original, resizing it for this example.
    Dim bmp2 As New Bitmap(bmp1, New Size(80, 80))

    bmp1.Dispose()

    ' Create an ImageAttributes object.
    Dim imgAttributes As New System.Drawing.Imaging.ImageAttributes()

    ' Draw the image unaltered.
    e.Graphics.DrawImage(bmp2, 10, 10)

    ' Draw the image, showing the intensity of the cyan channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelC, ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(100, 10, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    ' Draw the image, showing the intensity of the magenta channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelM, ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(10, 100, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    ' Draw the image, showing the intensity of the yellow channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelY, _
        ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(100, 100, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    ' Draw the image, showing the intensity of the black channel.
    imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelK, _
        ColorAdjustType.Bitmap)

    e.Graphics.DrawImage(bmp2, New Rectangle(10, 190, bmp2.Width, bmp2.Height), _
        0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel, imgAttributes)

    'Dispose of the bitmap.
    bmp2.Dispose()

End Sub

注解

可以使用SetOutputChannel方法将图像转换为 cmyk 颜色空间, 并检查其中一个 cmyk 颜色通道的浓度。You can use the SetOutputChannel method to convert an image to a CMYK color space and examine the intensities of one of the CMYK color channels. 例如, 假设您创建了一个ImageAttributes对象, 并将其位图输出通道ColorChannelC设置为。For example, suppose you create an ImageAttributes object and set its bitmap output channel to ColorChannelC. 如果将该ImageAttributes对象的路径传递DrawImage给方法, 则会计算每个像素的青色分量, 并且呈现图像中的每个像素都是灰色阴影, 指示其青色通道的强度。If you pass the path of that ImageAttributes object to the DrawImage method, the cyan component of each pixel is calculated, and each pixel in the rendered image is a shade of gray that indicates the intensity of its cyan channel. 同样, 您可以呈现指示洋红色、黄色和黑色通道强度的图像。Similarly, you can render images that indicate the intensities of the magenta, yellow, and black channels.

ImageAttributes对象维护五个调整类别的颜色和灰度设置: 默认值、位图、画笔、笔和文本。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如, 可以为默认类别指定输出通道, 并为位图类别指定不同的输出通道。For example, you can specify an output channel for the default category and a different output channel for the bitmap category.

默认颜色调整和灰度调整设置适用于没有自己的调整设置的所有类别。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如, 如果您从未为位图类别指定任何调整设置, 则默认设置将应用到位图类别。For example, if you never specify any adjustment settings for the bitmap category, the default settings apply to the bitmap category.

为某个类别指定颜色调整或灰度调整设置后, 默认调整设置将不再应用于该类别。As soon as you specify a color-adjustment or grayscale-adjustment setting for a certain category, the default adjustment settings no longer apply to that category. 例如, 假设您为默认类别指定了调整设置的集合。For example, suppose you specify a collection of adjustment settings for the default category. 如果通过将传递Bitmap SetOutputChannel给方法来设置位图类别的输出通道, 则没有任何默认调整设置将应用于位图。If you set the output channel for the bitmap category by passing Bitmap to the SetOutputChannel method, none of the default adjustment settings will apply to bitmaps.

适用于