ImageAttributes.SetRemapTable 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定色彩重新對應數據表。
多載
SetRemapTable(ColorMap[])
設定預設類別的色彩重新對應數據表。
public:
void SetRemapTable(cli::array <System::Drawing::Imaging::ColorMap ^> ^ map);
public:
void SetRemapTable(... cli::array <System::Drawing::Imaging::ColorMap ^> ^ map);
public void SetRemapTable (System.Drawing.Imaging.ColorMap[] map);
public void SetRemapTable (params System.Drawing.Imaging.ColorMap[] map);
member this.SetRemapTable : System.Drawing.Imaging.ColorMap[] -> unit
Public Sub SetRemapTable (map As ColorMap())
Public Sub SetRemapTable (ParamArray map As ColorMap())
參數
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
建立影像(紅色圓圈)、將它儲存為 Circle2.jpg、開啟該影像,並將它繪製到螢幕。
建立色彩對應,將紅色對應至綠色。
再次將稍早建立的影像繪製到畫面,但這次會使用色圖。
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 結構的陣列。 每個 ColorMap 結構都有兩個 Color 物件:一個指定舊色彩,另一個指定對應的新色彩。 在轉譯期間,任何符合重新對應數據表中其中一個舊色彩的色彩,會變更為對應的新色彩。
ImageAttributes 物件會維護五個調整類別的色彩和灰階設定:預設、位圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的色彩重新對應、點陣圖類別的色彩重新對應數據表,以及畫筆類別的不同色彩重新對應表格。
默認色彩調整和灰階調整設定適用於沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。
適用於
SetRemapTable(ReadOnlySpan<ColorMap>)
public:
void SetRemapTable(ReadOnlySpan<System::Drawing::Imaging::ColorMap ^> map);
public void SetRemapTable (scoped ReadOnlySpan<System.Drawing.Imaging.ColorMap> map);
member this.SetRemapTable : ReadOnlySpan<System.Drawing.Imaging.ColorMap> -> unit
Public Sub SetRemapTable (map As ReadOnlySpan(Of ColorMap))
參數
- map
- ReadOnlySpan<ColorMap>
適用於
SetRemapTable(ReadOnlySpan<ValueTuple<Color,Color>>)
public:
void SetRemapTable(ReadOnlySpan<ValueTuple<System::Drawing::Color, System::Drawing::Color>> map);
public void SetRemapTable (scoped ReadOnlySpan<(System.Drawing.Color OldColor, System.Drawing.Color NewColor)> map);
member this.SetRemapTable : ReadOnlySpan<ValueTuple<System.Drawing.Color, System.Drawing.Color>> -> unit
Public Sub SetRemapTable (map As ReadOnlySpan(Of ValueTuple(Of Color, Color)))
參數
- map
- ReadOnlySpan<ValueTuple<Color,Color>>
適用於
SetRemapTable(ColorAdjustType, ReadOnlySpan<ColorMap>)
public:
void SetRemapTable(System::Drawing::Imaging::ColorAdjustType type, ReadOnlySpan<System::Drawing::Imaging::ColorMap ^> map);
public void SetRemapTable (System.Drawing.Imaging.ColorAdjustType type, scoped ReadOnlySpan<System.Drawing.Imaging.ColorMap> map);
member this.SetRemapTable : System.Drawing.Imaging.ColorAdjustType * ReadOnlySpan<System.Drawing.Imaging.ColorMap> -> unit
Public Sub SetRemapTable (type As ColorAdjustType, map As ReadOnlySpan(Of ColorMap))
參數
- type
- ColorAdjustType
- map
- ReadOnlySpan<ColorMap>
適用於
SetRemapTable(ColorAdjustType, ReadOnlySpan<ValueTuple<Color,Color>>)
public:
void SetRemapTable(System::Drawing::Imaging::ColorAdjustType type, ReadOnlySpan<ValueTuple<System::Drawing::Color, System::Drawing::Color>> map);
public void SetRemapTable (System.Drawing.Imaging.ColorAdjustType type, scoped ReadOnlySpan<(System.Drawing.Color OldColor, System.Drawing.Color NewColor)> map);
member this.SetRemapTable : System.Drawing.Imaging.ColorAdjustType * ReadOnlySpan<ValueTuple<System.Drawing.Color, System.Drawing.Color>> -> unit
Public Sub SetRemapTable (type As ColorAdjustType, map As ReadOnlySpan(Of ValueTuple(Of Color, Color)))
參數
- type
- ColorAdjustType
- map
- ReadOnlySpan<ValueTuple<Color,Color>>
適用於
SetRemapTable(ColorMap[], ColorAdjustType)
設定指定類別的色彩重新對應數據表。
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)
參數
- type
- ColorAdjustType
ColorAdjustType 的 元素,指定色彩重新對應數據表設定的類別。
範例
如需程式代碼範例,請參閱 SetRemapTable(ColorMap[]) 方法。
備註
色彩重新對應數據表是 ColorMap 結構的陣列。 每個 ColorMap 結構都有兩個 Color 物件:一個指定舊色彩,另一個指定對應的新色彩。 在轉譯期間,任何符合重新對應數據表中其中一個舊色彩的色彩,會變更為對應的新色彩。
ImageAttributes 物件會維護五個調整類別的色彩和灰階設定:預設、位圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的色彩重新對應、點陣圖類別的色彩重新對應數據表,以及畫筆類別的不同色彩重新對應表格。
默認色彩調整和灰階調整設定適用於沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。
一旦您指定特定類別的色彩調整或灰階調整設定,預設調整設定就不再套用至該類別。 例如,假設您指定預設類別的調整設定集合。 如果您藉由將 Pen 傳遞至 SetRemapTable 方法來設定畫筆類別的色彩重新對應表格,則默認調整設定都不會套用至畫筆。