다음을 통해 공유


ColorMatrix 클래스

정의

RGBAW 공간에 대한 좌표를 포함하는 5 x 5 행렬을 정의합니다. 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 추가

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

다시 칠하기

색 행렬의 요소는 행을 기준으로 인덱싱된 다음 열을 기준으로 인덱싱됩니다. 예를 들어 행렬 M의 다섯 번째 행과 세 번째 열에 있는 항목은 M[4][2]로 표시됩니다.

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

다시 칠하기

행렬 및 변환에 대한 자세한 내용은 좌표계 및 변환참조하세요.

생성자

ColorMatrix()

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

ColorMatrix(ReadOnlySpan<Single>)

RGBAW 공간에 대한 좌표를 포함하는 5 x 5 행렬을 정의합니다. ImageAttributes 클래스의 여러 메서드는 색 행렬을 사용하여 이미지 색을 조정합니다. 이 클래스는 상속할 수 없습니다.

ColorMatrix(Single[][])

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

속성

Item[Int32, Int32]

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

Matrix00

ColorMatrix0행과 0열의 요소를 가져오거나 설정합니다.

Matrix01

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

Matrix02

ColorMatrix0행과 두 번째 열에 있는 요소를 가져오거나 설정합니다.

Matrix03

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

Matrix04

ColorMatrix0행과 네 번째 열에 있는 요소를 가져오거나 설정합니다.

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)

적용 대상

추가 정보

  • 이미지 다시 칠하기