ImageAttributes.SetColorMatrix メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ImageAttributes.SetColorMatrix メソッドの意味・解説 

ImageAttributes.SetColorMatrix メソッド (ColorMatrix)

既定カテゴリカラー調整行列設定します

名前空間: System.Drawing.Imaging
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub SetColorMatrix ( _
    newColorMatrix As ColorMatrix _
)
Dim instance As ImageAttributes
Dim newColorMatrix As ColorMatrix

instance.SetColorMatrix(newColorMatrix)
public void SetColorMatrix (
    ColorMatrix newColorMatrix
)
public:
void SetColorMatrix (
    ColorMatrix^ newColorMatrix
)
public void SetColorMatrix (
    ColorMatrix newColorMatrix
)
public function SetColorMatrix (
    newColorMatrix : ColorMatrix
)

パラメータ

newColorMatrix

カラー調整行列

戻り値
このメソッドは値を返しません。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

  1. すべてのカラー値が 128設定され四角形イメージ作成し灰色塗りつぶされ四角形にします。次にこのコードは、この四角形イメージ画面描画ます。

  2. ColorMatrix を作成し、その Matrix 位置を 1.75 に設定します。それにより、このイメージの赤の要素強調されます。

  3. ImageAttributes オブジェクト作成し、SetColorMatrix メソッド呼び出します。

  4. ImageAttributes オブジェクト内に設定されColorMatrix使用してイメージ (2 回目四角形) を画面描画ます。

2 回目四角形は赤が強調されていることに注意してください

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
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);      
    
}
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.get_Graphics().DrawImage(myImage, 20, 20);

    // Initialize the color matrix.
    ColorMatrix myColorMatrix = new ColorMatrix();

    // Red
    myColorMatrix.set_Matrix00(1.75F);

    // Green
    myColorMatrix.set_Matrix11(1);

    // Blue
    myColorMatrix.set_Matrix22(1);

    // alpha
    myColorMatrix.set_Matrix33(1);

    // w
    myColorMatrix.set_Matrix44(1);

    // 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.get_Graphics().DrawImage(myImage, rect, 0, 0, 200, 200, 
        GraphicsUnit.Pixel, imageAttr);
} //SetColorMatrixExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ImageAttributes.SetColorMatrix メソッド (ColorMatrix, ColorMatrixFlag, ColorAdjustType)

指定したカテゴリカラー調整行列設定します

名前空間: System.Drawing.Imaging
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub SetColorMatrix ( _
    newColorMatrix As ColorMatrix, _
    mode As ColorMatrixFlag, _
    type As ColorAdjustType _
)
Dim instance As ImageAttributes
Dim newColorMatrix As ColorMatrix
Dim mode As ColorMatrixFlag
Dim type As ColorAdjustType

instance.SetColorMatrix(newColorMatrix, mode, type)
public void SetColorMatrix (
    ColorMatrix newColorMatrix,
    ColorMatrixFlag mode,
    ColorAdjustType type
)
public:
void SetColorMatrix (
    ColorMatrix^ newColorMatrix, 
    ColorMatrixFlag mode, 
    ColorAdjustType type
)
public void SetColorMatrix (
    ColorMatrix newColorMatrix, 
    ColorMatrixFlag mode, 
    ColorAdjustType type
)
public function SetColorMatrix (
    newColorMatrix : ColorMatrix, 
    mode : ColorMatrixFlag, 
    type : ColorAdjustType
)

パラメータ

newColorMatrix

カラー調整行列

mode

カラー調整行列影響を受けるイメージと色の種類指定する ColorMatrixFlag の要素

type

カラー調整行列設定する対象カテゴリ指定する ColorAdjustType の要素

戻り値
このメソッドは値を返しません。

解説解説
使用例使用例

SetColorMatrix メソッド使用する方法次のコード例示します。この例を実行するには、コードWindows フォーム貼り付けフォームPaint イベント処理メソッドから、e を PaintEventArgs として渡すことにより、RotateColors呼び出します。

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
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);

}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ImageAttributes クラス
ImageAttributes メンバ
System.Drawing.Imaging 名前空間

ImageAttributes.SetColorMatrix メソッド (ColorMatrix, ColorMatrixFlag)

既定カテゴリカラー調整行列設定します

名前空間: System.Drawing.Imaging
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub SetColorMatrix ( _
    newColorMatrix As ColorMatrix, _
    flags As ColorMatrixFlag _
)
Dim instance As ImageAttributes
Dim newColorMatrix As ColorMatrix
Dim flags As ColorMatrixFlag

instance.SetColorMatrix(newColorMatrix, flags)
public void SetColorMatrix (
    ColorMatrix newColorMatrix,
    ColorMatrixFlag flags
)
public:
void SetColorMatrix (
    ColorMatrix^ newColorMatrix, 
    ColorMatrixFlag flags
)
public void SetColorMatrix (
    ColorMatrix newColorMatrix, 
    ColorMatrixFlag flags
)
public function SetColorMatrix (
    newColorMatrix : ColorMatrix, 
    flags : ColorMatrixFlag
)

パラメータ

newColorMatrix

カラー調整行列

flags

カラー調整行列影響を受けるイメージと色の種類指定する ColorMatrixFlag の要素

戻り値
このメソッドは値を返しません。

解説解説
使用例使用例

コード例については、SetColorMatrix(ColorMatrix) メソッドトピック参照してください

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ImageAttributes.SetColorMatrix メソッド

カラー調整行列設定します
オーバーロードの一覧オーバーロードの一覧

名前 説明
ImageAttributes.SetColorMatrix (ColorMatrix) 既定カテゴリカラー調整行列設定します
ImageAttributes.SetColorMatrix (ColorMatrix, ColorMatrixFlag) 既定カテゴリカラー調整行列設定します
ImageAttributes.SetColorMatrix (ColorMatrix, ColorMatrixFlag, ColorAdjustType) 指定したカテゴリカラー調整行列設定します
参照参照

関連項目

ImageAttributes クラス
ImageAttributes メンバ
System.Drawing.Imaging 名前空間

その他の技術情報

イメージ色の変更



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ImageAttributes.SetColorMatrix メソッド」の関連用語

ImageAttributes.SetColorMatrix メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ImageAttributes.SetColorMatrix メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS