ImageAttributes.SetRemapTable 方法

定義

設定色彩重新對應表。Sets the color-remap table.

多載

SetRemapTable(ColorMap[])

設定預設分類的色彩重新對應表。Sets the color-remap table for the default category.

SetRemapTable(ColorMap[], ColorAdjustType)

設定指定分類的色彩重新對應表。Sets the color-remap table for a specified category.

SetRemapTable(ColorMap[])

設定預設分類的色彩重新對應表。Sets the color-remap table for the default category.

public:
 void SetRemapTable(cli::array <System::Drawing::Imaging::ColorMap ^> ^ map);
public void SetRemapTable (System.Drawing.Imaging.ColorMap[] map);
member this.SetRemapTable : System.Drawing.Imaging.ColorMap[] -> unit
Public Sub SetRemapTable (map As ColorMap())

參數

map
ColorMap[]

ColorMap 型別的色彩配對陣列。An array of color pairs of type ColorMap. 每個色彩配對包含現有色彩 (第一個值) 和現有色彩所要對應至的色彩 (第二個值)。Each color pair contains an existing color (the first value) and the color that it will be mapped to (the second value).

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計, 而且PaintEventArgs它需要e, 這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  1. 建立影像 (紅色圓形)、將其儲存為 Circle2、開啟該影像, 並將其繪製到螢幕。Creates an image (a red circle), saves it as Circle2.jpg, opens that image, and draws it to the screen.

  2. 建立色彩對應, 將紅色的色彩對應到綠色的色彩。Creates a color map that maps the color red to the color green.

  3. 將稍早建立的影像繪製到螢幕上, 但這次使用色彩對應。Draws the image created earlier to the screen again, but this time using the color map.

private:
   void SetRemapTableExample( PaintEventArgs^ e )
   {
      // Create a filled, red image, and save it to Circle2.jpg.
      Bitmap^ myBitmap = gcnew Bitmap( 50,50 );
      Graphics^ g = Graphics::FromImage( myBitmap );
      g->Clear( Color::White );
      g->FillEllipse( gcnew SolidBrush( Color::Red ), Rectangle(0,0,50,50) );
      myBitmap->Save( "Circle2.jpg" );

      // Create an Image object from the Circle2.jpg file, and draw it to
      // the screen.
      Image^ myImage = Image::FromFile( "Circle2.jpg" );
      e->Graphics->DrawImage( myImage, 20, 20 );

      // Create a color map.
      array<ColorMap^>^myColorMap = gcnew array<ColorMap^>(1);
      myColorMap[ 0 ] = gcnew ColorMap;
      myColorMap[ 0 ]->OldColor = Color::Red;
      myColorMap[ 0 ]->NewColor = Color::Green;

      // Create an ImageAttributes object, and then pass the
      // myColorMap object to the SetRemapTable method.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetRemapTable( myColorMap );

      // Draw the image with the remap table set.
      Rectangle rect = Rectangle(150,20,50,50);
      e->Graphics->DrawImage( myImage, rect, 0, 0, 50, 50, GraphicsUnit::Pixel, imageAttr );
   }
private void SetRemapTableExample(PaintEventArgs e)
{
             
    // Create a filled, red image, and save it to Circle2.jpg.
    Bitmap myBitmap = new Bitmap(50, 50);
    Graphics g = Graphics.FromImage(myBitmap);
    g.Clear(Color.White);
    g.FillEllipse(new SolidBrush(Color.Red),
        new Rectangle(0, 0, 50, 50));
    myBitmap.Save("Circle2.jpg");
             
    // Create an Image object from the Circle2.jpg file, and draw it to
             
    // the screen.
    Image myImage = Image.FromFile("Circle2.jpg");
    e.Graphics.DrawImage(myImage, 20, 20);
             
    // Create a color map.
    ColorMap[] myColorMap = new ColorMap[1];
    myColorMap[0] = new ColorMap();
    myColorMap[0].OldColor = Color.Red;
    myColorMap[0].NewColor = Color.Green;
             
    // Create an ImageAttributes object, and then pass the
   // myColorMap object to the SetRemapTable method.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetRemapTable(myColorMap);
             
    // Draw the image with the remap table set.
    Rectangle rect = new Rectangle(150, 20, 50, 50);
    e.Graphics.DrawImage(myImage, rect, 0, 0, 50, 50, 
        GraphicsUnit.Pixel, imageAttr);    
   
}
Public Sub SetRemapTableExample(ByVal e As PaintEventArgs)

    ' Create a filled, red image and save it to Circle2.jpg.
    Dim myBitmap As New Bitmap(50, 50)
    Dim g As Graphics = Graphics.FromImage(myBitmap)
    g.Clear(Color.White)
    g.FillEllipse(New SolidBrush(Color.Red), New Rectangle(0, 0, _
    50, 50))
    myBitmap.Save("Circle2.jpg")

    ' Create an Image object from the Circle2.jpg file, and draw

    ' it to the screen.
    Dim myImage As Image = Image.FromFile("Circle2.jpg")
    e.Graphics.DrawImage(myImage, 20, 20)

    ' Create a color map.
    Dim myColorMap(0) As ColorMap
    myColorMap(0) = New ColorMap
    myColorMap(0).OldColor = Color.Red
    myColorMap(0).NewColor = Color.Green

    ' Create an ImageAttributes object, and then pass the

    ' myColorMap object to the SetRemapTable method.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetRemapTable(myColorMap)

    ' Draw the image with the remap table set.
    Dim rect As New Rectangle(150, 20, 50, 50)
    e.Graphics.DrawImage(myImage, rect, 0, 0, 50, 50, _
    GraphicsUnit.Pixel, imageAttr)
    ' Image
End Sub

備註

色彩重新對應表是結構的ColorMap陣列。A color-remap table is an array of ColorMap structures. ColorMap個結構都Color有兩個物件: 一個指定舊的色彩, 另一個則指定對應的新色彩。Each ColorMap structure has two Color objects: one that specifies an old color and one that specifies a corresponding new color. 在轉譯期間, 符合重新對應表中一種舊色彩的任何色彩都會變更為相對應的新色彩。During rendering, any color that matches one of the old colors in the remap table is changed to the corresponding new color.

ImageAttributes物件會維護五個調整類別的色彩和灰階設定: 預設、點陣圖、筆刷、畫筆和文字。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如, 您可以指定預設分類的色彩重新對應、點陣圖類別的色彩重新對應表, 以及畫筆類別目錄的不同色彩重新對應表。For example, you can specify a color remap for the default category, a color-remap table for the bitmap category, and still a different color-remap table for the pen category.

預設的彩色調整和灰階調整設定適用于沒有自己的調整設定的所有類別。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如, 如果您從未針對 [畫筆] 分類指定任何調整設定, 則預設設定會套用至 [畫筆] 分類。For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

SetRemapTable(ColorMap[], ColorAdjustType)

設定指定分類的色彩重新對應表。Sets the color-remap table for a specified category.

public:
 void SetRemapTable(cli::array <System::Drawing::Imaging::ColorMap ^> ^ map, System::Drawing::Imaging::ColorAdjustType type);
public void SetRemapTable (System.Drawing.Imaging.ColorMap[] map, System.Drawing.Imaging.ColorAdjustType type);
member this.SetRemapTable : System.Drawing.Imaging.ColorMap[] * System.Drawing.Imaging.ColorAdjustType -> unit
Public Sub SetRemapTable (map As ColorMap(), type As ColorAdjustType)

參數

map
ColorMap[]

ColorMap 型別的色彩配對陣列。An array of color pairs of type ColorMap. 每個色彩配對包含現有色彩 (第一個值) 和現有色彩所要對應至的色彩 (第二個值)。Each color pair contains an existing color (the first value) and the color that it will be mapped to (the second value).

type
ColorAdjustType

ColorAdjustType 的項目,指定已設定色彩重新對應表的分類。An element of ColorAdjustType that specifies the category for which the color-remap table is set.

範例

如需程式碼範例, 請SetRemapTable(ColorMap[])參閱方法。For a code example, see the SetRemapTable(ColorMap[]) method.

備註

色彩重新對應表是結構的ColorMap陣列。A color-remap table is an array of ColorMap structures. ColorMap個結構都Color有兩個物件: 一個指定舊的色彩, 另一個則指定對應的新色彩。Each ColorMap structure has two Color objects: one that specifies an old color and one that specifies a corresponding new color. 在轉譯期間, 符合重新對應表中一種舊色彩的任何色彩都會變更為相對應的新色彩。During rendering, any color that matches one of the old colors in the remap table is changed to the corresponding new color.

ImageAttributes物件會維護五個調整類別的色彩和灰階設定: 預設、點陣圖、筆刷、畫筆和文字。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如, 您可以指定預設分類的色彩重新對應、點陣圖類別的色彩重新對應表, 以及畫筆類別目錄的不同色彩重新對應表。For example, you can specify a color remap for the default category, a color-remap table for the bitmap category, and still a different color-remap table for the pen category.

預設的彩色調整和灰階調整設定適用于沒有自己的調整設定的所有類別。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如, 如果您從未針對 [畫筆] 分類指定任何調整設定, 則預設設定會套用至 [畫筆] 分類。For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

當您指定特定分類的彩色調整或灰階調整設定時, 預設調整設定就不再適用于該類別。As soon as you specify a color-adjustment or grayscale-adjustment setting for a certain category, the default adjustment settings no longer apply to that category. 例如, 假設您為預設分類指定調整設定的集合。For example, suppose you specify a collection of adjustment settings for the default category. 如果您藉由傳遞Pen SetRemapTable至方法來設定畫筆類別的色彩重新對應表, 則不會將任何預設的調整設定套用到畫筆。If you set the color-remap table for the pen category by passing Pen to the SetRemapTable method, none of the default adjustment settings will apply to pens.

適用於