既定のカテゴリのカラー調整行列を設定します。
Overloads Public Sub SetColorMatrix( _
ByVal newColorMatrix As ColorMatrix _)
[C#]
public void SetColorMatrix(ColorMatrixnewColorMatrix);
[C++]
public: void SetColorMatrix(ColorMatrix* newColorMatrix);
[JScript]
public function SetColorMatrix(
newColorMatrix : ColorMatrix);
パラメータ
- newColorMatrix
カラー調整行列。
戻り値
このメソッドは値を返しません。
解説
ImageAttributes オブジェクトは、5 つの調整カテゴリ (既定、ビットマップ、ブラシ、ペン、テキスト) に関して色とグレースケールの設定を保持します。たとえば、既定のカテゴリにあるカラー調整行列を指定し、ビットマップ カテゴリには別のカラー調整行列を指定し、さらにペン カテゴリにも異なるカラー調整行列を指定できます。
既定のカラー調整設定値およびグレースケール調整設定値は、調整設定値が設定されていないすべてのカテゴリに対して適用されます。たとえば、ペン カテゴリの調整設定を一切指定していない場合、ペン カテゴリには既定の設定が適用されます。
myImageAttributes.SetColorMatrix(cm) 呼び出しは、myImageAttributes.SetColorMatrix(cm, ColorMatrixFlag.Default) 呼び出しと同等です。ColorMatrixFlags.Default は、すべての色 (灰色を含む) がカラー調整行列で調整されるように指定します。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- すべてのカラー値が 128 に設定された四角形イメージを作成し、灰色で塗りつぶされた四角形にします。次にこのコードは、この四角形イメージを画面に描画します。
- ColorMatrix オブジェクトを作成し、その Matrix00 位置を 1.75 に設定します。それにより、このイメージの赤のコンポーネントが強調されます。
- ImageAttributes オブジェクトを作成し、 SetColorMatrix メソッドを呼び出します。
- ImageAttributes オブジェクト内に設定された ColorMatrix オブジェクトを使用して、イメージ (2 回目の四角形) を画面に描画します。
[Visual Basic, C#] 2 回目の四角形は赤が強調されていることに注意してください。
Public Sub SetColorMatrixExample(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 = 1F ' Green
myColorMatrix.Matrix22 = 1F ' Blue
myColorMatrix.Matrix33 = 1F ' alpha
myColorMatrix.Matrix44 = 1F ' 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
[C#]
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();
myColorMatrix.Matrix00 = 1.75f; // Red
myColorMatrix.Matrix11 = 1.00f; // Green
myColorMatrix.Matrix22 = 1.00f; // Blue
myColorMatrix.Matrix33 = 1.00f; // alpha
myColorMatrix.Matrix44 = 1.00f; // w
// 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, // Image
rect, // Dest. rect.
0, // srcX
0, // srcY
200, // srcWidth
200, // srcHeight
GraphicsUnit.Pixel, // srcUnit
imageAttr); // ImageAttributes
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
ImageAttributes クラス | ImageAttributes メンバ | System.Drawing.Imaging 名前空間 | ImageAttributes.SetColorMatrix オーバーロードの一覧