ImageAttributes.SetWrapMode 方法

定义

设置环绕模式。

重载

SetWrapMode(WrapMode)

设置环绕模式,该模式用于决定如何将纹理平铺到一个形状上或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

SetWrapMode(WrapMode, Color)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

SetWrapMode(WrapMode, Color, Boolean)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

SetWrapMode(WrapMode)

Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
Source:
ImageAttributes.cs

设置环绕模式,该模式用于决定如何将纹理平铺到一个形状上或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

public:
 void SetWrapMode(System::Drawing::Drawing2D::WrapMode mode);
public void SetWrapMode (System.Drawing.Drawing2D.WrapMode mode);
member this.SetWrapMode : System.Drawing.Drawing2D.WrapMode -> unit
Public Sub SetWrapMode (mode As WrapMode)

参数

mode
WrapMode

WrapMode 的一个元素,它指定使用重复的图像副本平铺区域的方式。

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  1. Image从 Circle3.jpg 文件中打开, (一个红色的小圆) ,并将其绘制到屏幕上。

  2. 创建 一个 ImageAttributes 对象,并将 WrapMode 枚举设置为 Tile

  3. TextureBrush使用 Circle3.jpg 文件中的映像创建 。

  4. 向填充红色小圆圈的屏幕绘制一个矩形。

void SetWrapModeExample( PaintEventArgs^ e )
{
   // Create a filled, red circle, and save it to Circle3.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,25,25) );
   myBitmap->Save( "Circle3.jpg" );

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

   // Set the wrap mode.
   ImageAttributes^ imageAttr = gcnew ImageAttributes;
   imageAttr->SetWrapMode( WrapMode::Tile );

   // Create a TextureBrush.
   Rectangle brushRect = Rectangle(0,0,25,25);
   TextureBrush^ myTBrush = gcnew TextureBrush( myImage,brushRect,imageAttr );

   // Draw to the screen a rectangle filled with red circles.
   e->Graphics->FillRectangle( myTBrush, 100, 20, 200, 200 );
}
private void SetWrapModeExample(PaintEventArgs e)
{
             
    // Create a filled, red circle, and save it to Circle3.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, 25, 25));
    myBitmap.Save("Circle3.jpg");
             
    // Create an Image object from the Circle3.jpg file, and draw it
    // to the screen.
    Image myImage = Image.FromFile("Circle3.jpg");
    e.Graphics.DrawImage(myImage, 20, 20);
             
    // Set the wrap mode.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetWrapMode(WrapMode.Tile);
             
    // Create a TextureBrush.
    Rectangle brushRect = new Rectangle(0,0,25,25);
    TextureBrush myTBrush = new TextureBrush(myImage, brushRect, imageAttr);
             
    // Draw to the screen a rectangle filled with red circles.
    e.Graphics.FillRectangle(myTBrush, 100, 20, 200, 200);
}
Public Sub SetWrapModeExample(ByVal e As PaintEventArgs)

    ' Create a filled, red circle, and save it to Circle3.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, _
    25, 25))
    myBitmap.Save("Circle3.jpg")

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

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

    ' Set the wrap mode.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetWrapMode(WrapMode.Tile)

    ' Create a TextureBrush.
    Dim brushRect As New Rectangle(0, 0, 25, 25)
    Dim myTBrush As New TextureBrush(myImage, brushRect, imageAttr)

    ' Draw to the screen a rectangle filled with red circles.
    e.Graphics.FillRectangle(myTBrush, 100, 20, 200, 200)
End Sub

注解

SetWrapMode(WrapMode)调用 方法等效于对 color 参数调用SetWrapMode(WrapMode, Color)Color.Black和传递。 Color.Black 指定呈现图像外部的像素的颜色。 如果 mode 参数设置为 Clamp ,并且传递给 DrawImage 方法的源矩形大于图像本身,则此颜色可见。

适用于

SetWrapMode(WrapMode, Color)

Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
Source:
ImageAttributes.cs

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

public:
 void SetWrapMode(System::Drawing::Drawing2D::WrapMode mode, System::Drawing::Color color);
public void SetWrapMode (System.Drawing.Drawing2D.WrapMode mode, System.Drawing.Color color);
member this.SetWrapMode : System.Drawing.Drawing2D.WrapMode * System.Drawing.Color -> unit
Public Sub SetWrapMode (mode As WrapMode, color As Color)

参数

mode
WrapMode

WrapMode 的一个元素,它指定使用重复的图像副本平铺区域的方式。

color
Color

一个 ImageAttributes 对象,指定所呈现图像外部的像素的颜色。 如果模式参数设置为 Clamp 并且传递给 DrawImage 的源矩形大于图像本身,则该颜色可见。

示例

有关代码示例,请参阅 SetWrapMode(WrapMode) 方法。

适用于

SetWrapMode(WrapMode, Color, Boolean)

Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
Source:
ImageAttributes.cs

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

public:
 void SetWrapMode(System::Drawing::Drawing2D::WrapMode mode, System::Drawing::Color color, bool clamp);
public void SetWrapMode (System.Drawing.Drawing2D.WrapMode mode, System.Drawing.Color color, bool clamp);
member this.SetWrapMode : System.Drawing.Drawing2D.WrapMode * System.Drawing.Color * bool -> unit
Public Sub SetWrapMode (mode As WrapMode, color As Color, clamp As Boolean)

参数

mode
WrapMode

WrapMode 的一个元素,它指定使用重复的图像副本平铺区域的方式。

color
Color

一个 Color 对象,指定所呈现图像外部的像素的颜色。 如果模式参数设置为 Clamp 并且传递给 DrawImage 的源矩形大于图像本身,则该颜色可见。

clamp
Boolean

此参数不起作用。 将其设置为 false

示例

有关代码示例,请参阅 SetWrapMode(WrapMode) 方法。

适用于