ImageAttributes.SetColorMatrix 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
색 조정 매트릭스를 설정합니다.
오버로드
SetColorMatrix(ColorMatrix) |
기본 범주에 대한 색 조정 매트릭스를 설정합니다. |
SetColorMatrix(ColorMatrix, ColorMatrixFlag) |
기본 범주에 대한 색 조정 매트릭스를 설정합니다. |
SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) |
지정된 범주에 대한 색 조정 매트릭스를 설정합니다. |
SetColorMatrix(ColorMatrix)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
기본 범주에 대한 색 조정 매트릭스를 설정합니다.
public:
void SetColorMatrix(System::Drawing::Imaging::ColorMatrix ^ newColorMatrix);
public void SetColorMatrix (System.Drawing.Imaging.ColorMatrix newColorMatrix);
member this.SetColorMatrix : System.Drawing.Imaging.ColorMatrix -> unit
Public Sub SetColorMatrix (newColorMatrix As ColorMatrix)
매개 변수
- newColorMatrix
- ColorMatrix
색 조정 매트릭스입니다.
예제
다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 처리기의 Paint 매개 변수인 가 필요합니다.PaintEventArgse
코드는 다음 작업을 수행합니다.
모든 색 값이 128로 설정된 사각형 이미지를 만들어 단색 중간 회색으로 채워진 사각형을 생성합니다. 그런 다음 코드는 이 사각형 이미지를 화면에 그립니다.
을 ColorMatrix 만들고 해당 Matrix 위치를 1.75로 설정하여 이미지의 빨간색 구성 요소를 강조합니다.
개체를 ImageAttributes 만들고 메서드를 호출합니다 SetColorMatrix .
개체의 방금 설정된 ImageAttributes 을 사용하여 ColorMatrix 이미지(두 번째 사각형)를 화면에 그립니다.
두 번째 사각형에는 빨간색이 강조되어 있습니다.
private:
void SetColorMatrixExample( PaintEventArgs^ e )
{
// Create a rectangle image with all colors set to 128 (medium
// gray).
Bitmap^ myBitmap = gcnew Bitmap( 50,50,PixelFormat::Format32bppArgb );
Graphics^ g = Graphics::FromImage( myBitmap );
g->FillRectangle( gcnew SolidBrush( Color::FromArgb( 255, 128, 128, 128 ) ), Rectangle(0,0,50,50) );
myBitmap->Save( "Rectangle1.jpg" );
// Open an Image file and draw it to the screen.
Image^ myImage = Image::FromFile( "Rectangle1.jpg" );
e->Graphics->DrawImage( myImage, 20, 20 );
// Initialize the color matrix.
ColorMatrix^ myColorMatrix = gcnew ColorMatrix;
// Red
myColorMatrix->Matrix00 = 1.75f;
// Green
myColorMatrix->Matrix11 = 1.00f;
// Blue
myColorMatrix->Matrix22 = 1.00f;
// alpha
myColorMatrix->Matrix33 = 1.00f;
// w
myColorMatrix->Matrix44 = 1.00f;
// Create an ImageAttributes object and set the color matrix.
ImageAttributes^ imageAttr = gcnew ImageAttributes;
imageAttr->SetColorMatrix( myColorMatrix );
// Draw the image using the color matrix.
Rectangle rect = Rectangle(100,20,200,200);
e->Graphics->DrawImage( myImage, rect, 0, 0, 200, 200, GraphicsUnit::Pixel, imageAttr );
}
private void SetColorMatrixExample(PaintEventArgs e)
{
// Create a rectangle image with all colors set to 128 (medium
// gray).
Bitmap myBitmap = new Bitmap(50, 50, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(myBitmap);
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 128, 128, 128)),
new Rectangle(0, 0, 50, 50));
myBitmap.Save("Rectangle1.jpg");
// Open an Image file and draw it to the screen.
Image myImage = Image.FromFile("Rectangle1.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
// Initialize the color matrix.
ColorMatrix myColorMatrix = new ColorMatrix();
// Red
myColorMatrix.Matrix00 = 1.75f;
// Green
myColorMatrix.Matrix11 = 1.00f;
// Blue
myColorMatrix.Matrix22 = 1.00f;
// alpha
myColorMatrix.Matrix33 = 1.00f;
// w
myColorMatrix.Matrix44 = 1.00f;
// Create an ImageAttributes object and set the color matrix.
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorMatrix(myColorMatrix);
// Draw the image using the color matrix.
Rectangle rect = new Rectangle(100, 20, 200, 200);
e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
GraphicsUnit.Pixel, imageAttr);
}
Public Sub SetColorMatrixExample(ByVal e As PaintEventArgs)
' Create a rectangle image with all colors set to 128 (medium
' gray).
Dim myBitmap As New Bitmap(50, 50, PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(myBitmap)
g.FillRectangle(New SolidBrush(Color.FromArgb(255, 128, 128, _
128)), New Rectangle(0, 0, 50, 50))
myBitmap.Save("Rectangle1.jpg")
' Open an Image file and draw it to the screen.
Dim myImage As Image = Image.FromFile("Rectangle1.jpg")
e.Graphics.DrawImage(myImage, 20, 20)
' Initialize the color matrix.
Dim myColorMatrix As New ColorMatrix
myColorMatrix.Matrix00 = 1.75F
' Red
myColorMatrix.Matrix11 = 1.0F
' Green
myColorMatrix.Matrix22 = 1.0F
' Blue
myColorMatrix.Matrix33 = 1.0F
' alpha
myColorMatrix.Matrix44 = 1.0F
' w
' Create an ImageAttributes object and set the color matrix.
Dim imageAttr As New ImageAttributes
imageAttr.SetColorMatrix(myColorMatrix)
' Draw the image using the color matrix.
Dim rect As New Rectangle(100, 20, 200, 200)
e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200, _
GraphicsUnit.Pixel, imageAttr)
' Image
End Sub
'SetColorMatrixExample
설명
개체는 ImageAttributes 기본, 비트맵, 브러시, 펜 및 텍스트의 다섯 가지 조정 범주에 대해 색 및 회색조 설정을 유지합니다. 예를 들어 기본 범주에 대한 색 조정 행렬, 비트맵 범주에 대한 다른 색 조정 행렬 및 펜 범주에 대해 다른 색 조정 매트릭스를 지정할 수 있습니다.
기본 색 조정 및 회색조 조정 설정은 자체 조정 설정이 없는 모든 범주에 적용됩니다. 예를 들어 펜 범주에 대한 조정 설정을 지정하지 않으면 기본 설정이 펜 범주에 적용됩니다.
메서드를 ImageAttributes.SetColorMatrix(ColorMatrix) 호출하는 것은 메서드를 ImageAttributes.SetColorMatrix(ColorMatrix, ColorMatrixFlag) 호출하고 매개 변수를 flags
전달하는 ColorMatrixFlag.Default 것과 같습니다. ColorMatrixFlag.Default 는 모든 색(회색 포함)이 색 조정 행렬에 의해 조정되도록 지정합니다.
추가 정보
적용 대상
SetColorMatrix(ColorMatrix, ColorMatrixFlag)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
기본 범주에 대한 색 조정 매트릭스를 설정합니다.
public:
void SetColorMatrix(System::Drawing::Imaging::ColorMatrix ^ newColorMatrix, System::Drawing::Imaging::ColorMatrixFlag flags);
public void SetColorMatrix (System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrixFlag flags);
member this.SetColorMatrix : System.Drawing.Imaging.ColorMatrix * System.Drawing.Imaging.ColorMatrixFlag -> unit
Public Sub SetColorMatrix (newColorMatrix As ColorMatrix, flags As ColorMatrixFlag)
매개 변수
- newColorMatrix
- ColorMatrix
색 조정 매트릭스입니다.
- flags
- ColorMatrixFlag
색 조정 매트릭스의 영향을 받을 색과 이미지의 형식을 지정하는 ColorMatrixFlag의 요소입니다.
예제
코드 예제는 메서드를 참조하세요 SetColorMatrix(ColorMatrix) .
설명
개체는 ImageAttributes 기본, 비트맵, 브러시, 펜 및 텍스트의 다섯 가지 조정 범주에 대해 색 및 회색조 설정을 유지합니다. 예를 들어 기본 범주에 대한 색 조정 행렬, 비트맵 범주에 대한 다른 색 조정 행렬 및 펜 범주에 대해 다른 색 조정 매트릭스를 지정할 수 있습니다.
기본 색 조정 및 회색조 조정 설정은 자체 조정 설정이 없는 모든 범주에 적용됩니다. 예를 들어 펜 범주에 대한 조정 설정을 지정하지 않으면 기본 설정이 펜 범주에 적용됩니다.
추가 정보
적용 대상
SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
지정된 범주에 대한 색 조정 매트릭스를 설정합니다.
public:
void SetColorMatrix(System::Drawing::Imaging::ColorMatrix ^ newColorMatrix, System::Drawing::Imaging::ColorMatrixFlag mode, System::Drawing::Imaging::ColorAdjustType type);
public void SetColorMatrix (System.Drawing.Imaging.ColorMatrix newColorMatrix, System.Drawing.Imaging.ColorMatrixFlag mode, System.Drawing.Imaging.ColorAdjustType type);
member this.SetColorMatrix : System.Drawing.Imaging.ColorMatrix * System.Drawing.Imaging.ColorMatrixFlag * System.Drawing.Imaging.ColorAdjustType -> unit
Public Sub SetColorMatrix (newColorMatrix As ColorMatrix, mode As ColorMatrixFlag, type As ColorAdjustType)
매개 변수
- newColorMatrix
- ColorMatrix
색 조정 매트릭스입니다.
- mode
- ColorMatrixFlag
색 조정 매트릭스의 영향을 받을 색과 이미지의 형식을 지정하는 ColorMatrixFlag의 요소입니다.
- type
- ColorAdjustType
색 조정 매트릭스가 설정되는 범주를 지정하는 ColorAdjustType의 요소입니다.
예제
다음 코드 예제에서는 SetColorMatrix 메서드를 사용하는 방법을 보여 줍니다. 이 예제를 실행하려면 코드를 Windows Form에 붙여넣고 양식의 Paint 이벤트 처리 메서드에서 를 호출 RotateColors
하여 로 PaintEventArgs전달 e
합니다.
private void RotateColors(PaintEventArgs e)
{
Bitmap image = new Bitmap("RotationInput.bmp");
ImageAttributes imageAttributes = new ImageAttributes();
int width = image.Width;
int height = image.Height;
float degrees = 60f;
double r = degrees * System.Math.PI / 180; // degrees to radians
float[][] colorMatrixElements = {
new float[] {(float)System.Math.Cos(r), (float)System.Math.Sin(r), 0, 0, 0},
new float[] {(float)-System.Math.Sin(r), (float)-System.Math.Cos(r), 0, 0, 0},
new float[] {0, 0, 2, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
e.Graphics.DrawImage(image, 10, 10, width, height);
e.Graphics.DrawImage(
image,
new Rectangle(150, 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);
}
Private Sub RotateColors(ByVal e As PaintEventArgs)
Dim image As Bitmap = New Bitmap("RotationInput.bmp")
Dim imageAttributes As New ImageAttributes()
Dim width As Integer = image.Width
Dim height As Integer = image.Height
Dim degrees As Single = 60.0F
Dim r As Double = degrees * System.Math.PI / 180 ' degrees to radians
Dim colorMatrixElements As Single()() = { _
New Single() {CSng(System.Math.Cos(r)), _
CSng(System.Math.Sin(r)), 0, 0, 0}, _
New Single() {CSng(-System.Math.Sin(r)), _
CSng(-System.Math.Cos(r)), 0, 0, 0}, _
New Single() {0, 0, 2, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {0, 0, 0, 0, 1}}
Dim colorMatrix As New ColorMatrix(colorMatrixElements)
imageAttributes.SetColorMatrix( _
colorMatrix, _
ColorMatrixFlag.Default, _
ColorAdjustType.Bitmap)
e.Graphics.DrawImage(image, 10, 10, width, height)
' Pass in the destination rectangle (2nd argument), the upper-left corner
' (3rd and 4th arguments), width (5th argument), and height (6th
' argument) of the source rectangle.
e.Graphics.DrawImage( _
image, _
New Rectangle(150, 10, width, height), _
0, 0, _
width, _
height, _
GraphicsUnit.Pixel, _
imageAttributes)
End Sub
설명
개체는 ImageAttributes 기본, 비트맵, 브러시, 펜 및 텍스트의 다섯 가지 조정 범주에 대해 색 및 회색조 설정을 유지합니다. 예를 들어 기본 범주에 대한 색 조정 행렬, 비트맵 범주에 대한 다른 색 조정 행렬 및 펜 범주에 대해 다른 색 조정 매트릭스를 지정할 수 있습니다.
기본 색 조정 및 회색조 조정 설정은 자체 조정 설정이 없는 모든 범주에 적용됩니다. 예를 들어 펜 범주에 대한 조정 설정을 지정하지 않으면 기본 설정이 펜 범주에 적용됩니다.
특정 범주에 대한 색 조정 또는 회색조 조정 설정을 지정하는 즉시 기본 조정 설정이 해당 범주에 더 이상 적용되지 않습니다. 예를 들어 기본 범주에 대한 조정 설정 컬렉션을 지정한다고 가정합니다. 메서드에 전달 Pen 하여 펜 범주의 색 조정 매트릭스를 SetColorMatrix 설정하는 경우 펜에 기본 조정 설정이 적용되지 않습니다.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기