ImageAttributes.SetWrapMode 方法

定义

设置环绕模式。Sets the wrap mode.

重载

SetWrapMode(WrapMode, Color)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

SetWrapMode(WrapMode)

设置环绕模式,该模式用于决定如何将纹理平铺到一个形状上或平铺到形状的边界上。Sets the wrap mode that is used to decide how to tile a texture across a shape, or at shape boundaries. 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

SetWrapMode(WrapMode, Color, Boolean)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

SetWrapMode(WrapMode, Color)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

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

参数

mode
WrapMode

WrapMode 的一个元素,它指定使用重复的图像副本平铺区域的方式。An element of WrapMode that specifies how repeated copies of an image are used to tile an area.

color
Color

一个 ImageAttributes 对象,指定所呈现图像外部的像素的颜色。An ImageAttributes object that specifies the color of pixels outside of a rendered image. 如果模式参数设置为 Clamp 并且传递给 DrawImage 的源矩形大于图像本身,则该颜色可见。This color is visible if the mode parameter is set to Clamp and the source rectangle passed to DrawImage is larger than the image itself.

示例

有关代码示例,请参阅 SetWrapMode(WrapMode) 方法。For a code example, see the SetWrapMode(WrapMode) method.

SetWrapMode(WrapMode)

设置环绕模式,该模式用于决定如何将纹理平铺到一个形状上或平铺到形状的边界上。Sets the wrap mode that is used to decide how to tile a texture across a shape, or at shape boundaries. 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

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 的一个元素,它指定使用重复的图像副本平铺区域的方式。An element of WrapMode that specifies how repeated copies of an image are used to tile an area.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要 PaintEventArgse,它是 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. 从 Circle3 文件打开 Image (一个小的红色实心圆圈),并将其绘制到屏幕上。Opens an Image from the Circle3.jpg file (a small, red-filled circle) and draws it to the screen.

  2. 创建 ImageAttributes 对象并将 WrapMode 枚举设置为 TileCreates an ImageAttributes object and sets the WrapMode enumeration to Tile.

  3. 使用 Circle3 文件中的图像创建 TextureBrushCreates a TextureBrush using the image from the Circle3.jpg file.

  4. 将一个矩形绘制到用红色实心小圆圈填充的屏幕上。Draws a rectangle to the screen that is filled with the small, red-filled circles.

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) 方法等效于调用 SetWrapMode(WrapMode, Color) 并传递 color 参数的 Color.BlackCalling the SetWrapMode(WrapMode) method is equivalent to calling SetWrapMode(WrapMode, Color) and passing Color.Black for the color parameter. Color.Black 指定所呈现图像外部的像素的颜色。Color.Black specifies the color of pixels outside of a rendered image. 如果 mode 参数设置为 Clamp 并且传递到 DrawImage 方法的源矩形大于图像本身,则会显示此颜色。This color is visible if the mode parameter is set to Clamp and the source rectangle passed to the DrawImage method is larger than the image itself.

SetWrapMode(WrapMode, Color, Boolean)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

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

参数

mode
WrapMode

WrapMode 的一个元素,它指定使用重复的图像副本平铺区域的方式。An element of WrapMode that specifies how repeated copies of an image are used to tile an area.

color
Color

一个 Color 对象,指定所呈现图像外部的像素的颜色。A color object that specifies the color of pixels outside of a rendered image. 如果模式参数设置为 Clamp 并且传递给 DrawImage 的源矩形大于图像本身,则该颜色可见。This color is visible if the mode parameter is set to Clamp and the source rectangle passed to DrawImage is larger than the image itself.

clamp
Boolean

此参数不起作用。This parameter has no effect. 将其设置为 falseSet it to false.

示例

有关代码示例,请参阅 SetWrapMode(WrapMode) 方法。For a code example, see the SetWrapMode(WrapMode) method.

适用于