ColorMatrix 클래스

정의

RGBAW 공간의 좌표를 포함하는 5x5 매트릭스를 정의합니다. ImageAttributes 클래스의 여러 메서드는 색 매트릭스를 사용하여 이미지 색을 조정합니다. 이 클래스는 상속될 수 없습니다.

public ref class ColorMatrix sealed
public sealed class ColorMatrix
type ColorMatrix = class
Public NotInheritable Class ColorMatrix
상속
ColorMatrix

예제

다음 예제에서는 모두 하나의 색(0.2, 0.0, 0.4, 1.0)인 이미지를 가져와 선행 단락에서 설명한 변환을 적용합니다.

다음 그림에서는 왼쪽에 원본 이미지, 오른쪽에 변환된 이미지를 보여줍니다.

색 색

다음 예제의 코드는 다음 단계를 사용하여 다시 칠하기 작업을 수행합니다.

  1. ColorMatrix 개체를 초기화합니다.

  2. ImageAttributes 개체를 만들고 ColorMatrix 개체를 ImageAttributes 개체의 SetColorMatrix 메서드로 전달합니다.

  3. ImageAttributes 개체를 Graphics 개체의 DrawImage 메서드로 전달합니다.

앞의 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 매개 변수 Paint 인 가 필요합니다.PaintEventArgse

Image image = new Bitmap("InputColor.bmp");
ImageAttributes imageAttributes = new ImageAttributes();
int width = image.Width;
int height = image.Height;

float[][] colorMatrixElements = { 
   new float[] {2,  0,  0,  0, 0},        // red scaling factor of 2
   new float[] {0,  1,  0,  0, 0},        // green scaling factor of 1
   new float[] {0,  0,  1,  0, 0},        // blue scaling factor of 1
   new float[] {0,  0,  0,  1, 0},        // alpha scaling factor of 1
   new float[] {.2f, .2f, .2f, 0, 1}};    // three translations of 0.2

ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

imageAttributes.SetColorMatrix(
   colorMatrix,
   ColorMatrixFlag.Default,
   ColorAdjustType.Bitmap);

e.Graphics.DrawImage(image, 10, 10);

e.Graphics.DrawImage(
   image,
   new Rectangle(120, 10, width, height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle 
   width,       // width of source rectangle
   height,      // height of source rectangle
   GraphicsUnit.Pixel,
   imageAttributes);
Dim image As New Bitmap("InputColor.bmp")
Dim imageAttributes As New ImageAttributes()
Dim width As Integer = image.Width
Dim height As Integer = image.Height

' The following matrix consists of the following transformations:
' red scaling factor of 2
' green scaling factor of 1
' blue scaling factor of 1
' alpha scaling factor of 1
' three translations of 0.2
Dim colorMatrixElements As Single()() = { _
   New Single() {2, 0, 0, 0, 0}, _
   New Single() {0, 1, 0, 0, 0}, _
   New Single() {0, 0, 1, 0, 0}, _
   New Single() {0, 0, 0, 1, 0}, _
   New Single() {0.2F, 0.2F, 0.2F, 0, 1}}

Dim colorMatrix As New ColorMatrix(colorMatrixElements)

imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap)

e.Graphics.DrawImage(image, 10, 10)

e.Graphics.DrawImage( _
   image, _
   New Rectangle(120, 10, width, height), _
   0, _
   0, _
   width, _
   height, _
   GraphicsUnit.Pixel, _
   imageAttributes)

설명

행렬 계수는 ARGB 동종 값을 변환하는 데 사용되는 5 x 5 선형 변환을 구성합니다. 예를 들어 ARGB 벡터는 빨강, 녹색, 파랑, 알파 및 w로 표시됩니다. 여기서 w는 항상 1입니다.

예를 들어 색 (0.2, 0.0, 0.4, 1.0)으로 시작하고 다음 변환을 적용하려는 경우를 가정합니다.

  1. 빨간색 구성 요소 배가

  2. 빨간색, 녹색 및 파란색 구성 요소에 0.2 추가

다음 행렬 곱셈은 나열된 순서대로 변환 쌍을 수행합니다.

다시 칠

색 행렬의 요소는 행과 열로 인덱싱됩니다(0부터). 예를 들어, 행렬 M의 다섯 번째 행과 세 번째 열에 있는 항목은 M[4][2]로 표시됩니다.

(다음 그림에 표시된) 5×5 ID 행렬은 대각선에서 1을, 다른 곳에서는 0을 가집니다. 색 벡터를 ID 행렬에 곱할 경우, 색 벡터는 변경되지 않습니다. 색 변환의 행렬을 형성하는 편리한 방법은 ID 행렬로 시작하고 원하는 변환을 생성하는 작은 변경을 만드는 것입니다.

다시 칠

행렬 및 변환에 대한 자세한 논의는 좌표계 및 변환을 참조하세요.

생성자

ColorMatrix()

ColorMatrix 클래스의 새 인스턴스를 초기화합니다.

ColorMatrix(ReadOnlySpan<Single>)

RGBAW 공간의 좌표를 포함하는 5x5 매트릭스를 정의합니다. ImageAttributes 클래스의 여러 메서드는 색 매트릭스를 사용하여 이미지 색을 조정합니다. 이 클래스는 상속될 수 없습니다.

ColorMatrix(Single[][])

지정된 newColorMatrix 매트릭스의 요소를 사용하여 ColorMatrix 클래스의 새 인스턴스를 초기화합니다.

속성

Item[Int32, Int32]

ColorMatrix의 지정된 행과 열에 있는 요소를 가져오거나 설정합니다.

Matrix00

ColorMatrix의 0행과 0열에 있는 요소를 가져오거나 설정합니다.

Matrix01

ColorMatrix의 0행과 첫째 열에 있는 요소를 가져오거나 설정합니다.

Matrix02

ColorMatrix의 0행과 둘째 열에 있는 요소를 가져오거나 설정합니다.

Matrix03

ColorMatrix의 0행과 셋째 열에 있는 요소를 가져오거나 설정합니다. 알파 구성 요소를 나타냅니다.

Matrix04

ColorMatrix의 0행과 넷째 열에 있는 요소를 가져오거나 설정합니다.

Matrix10

ColorMatrix의 첫째 행과 0열에 있는 요소를 가져오거나 설정합니다.

Matrix11

ColorMatrix의 첫째 행과 첫째 열에 있는 요소를 가져오거나 설정합니다.

Matrix12

ColorMatrix의 첫째 행과 둘째 열에 있는 요소를 가져오거나 설정합니다.

Matrix13

ColorMatrix의 첫째 행과 셋째 열에 있는 요소를 가져오거나 설정합니다. 알파 구성 요소를 나타냅니다.

Matrix14

ColorMatrix의 첫째 행과 넷째 열에 있는 요소를 가져오거나 설정합니다.

Matrix20

ColorMatrix의 둘째 행과 0열에 있는 요소를 가져오거나 설정합니다.

Matrix21

ColorMatrix의 둘째 행과 첫째 열에 있는 요소를 가져오거나 설정합니다.

Matrix22

ColorMatrix의 둘째 행과 둘째 열에 있는 요소를 가져오거나 설정합니다.

Matrix23

ColorMatrix의 둘째 행과 셋째 열에 있는 요소를 가져오거나 설정합니다.

Matrix24

ColorMatrix의 둘째 행과 넷째 열에 있는 요소를 가져오거나 설정합니다.

Matrix30

ColorMatrix의 셋째 행과 0열에 있는 요소를 가져오거나 설정합니다.

Matrix31

ColorMatrix의 셋째 행과 첫째 열에 있는 요소를 가져오거나 설정합니다.

Matrix32

ColorMatrix의 셋째 행과 둘째 열에 있는 요소를 가져오거나 설정합니다.

Matrix33

ColorMatrix의 셋째 행과 셋째 열에 있는 요소를 가져오거나 설정합니다. 알파 구성 요소를 나타냅니다.

Matrix34

ColorMatrix의 셋째 행과 넷째 열에 있는 요소를 가져오거나 설정합니다.

Matrix40

ColorMatrix의 넷째 행과 0열에 있는 요소를 가져오거나 설정합니다.

Matrix41

ColorMatrix의 넷째 행과 첫째 열에 있는 요소를 가져오거나 설정합니다.

Matrix42

ColorMatrix의 넷째 행과 둘째 열에 있는 요소를 가져오거나 설정합니다.

Matrix43

ColorMatrix의 넷째 행과 셋째 열에 있는 요소를 가져오거나 설정합니다. 알파 구성 요소를 나타냅니다.

Matrix44

ColorMatrix의 넷째 행과 넷째 열에 있는 요소를 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보