如何:在形状中平铺图像How to: Tile a Shape with an Image

就像可以彼此以涵盖地板放置磁贴,可以将矩形图像彼此放置于填充 (磁贴) 形状。Just as tiles can be placed next to each other to cover a floor, rectangular images can be placed next to each other to fill (tile) a shape. 若要磁贴形状的内部,使用纹理画笔。To tile the interior of a shape, use a texture brush. 当构造TextureBrush对象,将传递给构造函数的自变量之一为Image对象。When you construct a TextureBrush object, one of the arguments you pass to the constructor is an Image object. 纹理画笔用于绘制形状的内部,当填充形状与此图像的重复副本。When you use the texture brush to paint the interior of a shape, the shape is filled with repeated copies of this image.

自动换行模式属性的TextureBrush对象将决定如何图像的方向为矩形网格中重复。The wrap mode property of the TextureBrush object determines how the image is oriented as it is repeated in a rectangular grid. 您可以进行所有网格中的磁贴具有相同的方向,或者可以进行到下一个网格位置从翻转的图像。You can make all the tiles in the grid have the same orientation, or you can make the image flip from one grid position to the next. 翻转可以水平、 垂直,或两者。The flipping can be horizontal, vertical, or both. 下面的示例演示使用不同类型的翻转平铺。The following examples demonstrate tiling with different types of flipping.

平铺图像To tile an image

  • 此示例使用以下 75 × 75 映像磁贴 200 × 200 的矩形。This example uses the following 75×75 image to tile a 200×200 rectangle.

磁贴图像显示红色房屋和树。

  • 下图显示如何使用图像平铺矩形。The following illustration shows how the rectangle is tiled with the image. 请注意,所有磁贴具有相同方向;没有翻转。Note that all tiles have the same orientation; there is no flipping.

为所有图块使用相同的方向图像平铺的矩形。

Image image = new Bitmap("HouseAndTree.gif");
TextureBrush tBrush = new TextureBrush(image);
Pen blackPen = new Pen(Color.Black);
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
Dim image As New Bitmap("HouseAndTree.gif")
Dim tBrush As New TextureBrush(image)
Dim blackPen As New Pen(Color.Black)
e.Graphics.FillRectangle(tBrush, New Rectangle(0, 0, 200, 200))
e.Graphics.DrawRectangle(blackPen, New Rectangle(0, 0, 200, 200))

若要水平时平铺翻转图像To flip an image horizontally while tiling

  • 此示例使用相同 75 × 75 图像以填充 200 × 200 的矩形。This example uses the same 75×75 image to fill a 200×200 rectangle. 自动换行模式设置为水平翻转图像。The wrap mode is set to flip the image horizontally. 下图显示如何使用图像平铺矩形。The following illustration shows how the rectangle is tiled with the image. 请注意当您从一个磁贴移动到下一个给定行中,水平翻转图像。Note that as you move from one tile to the next in a given row, the image is flipped horizontally.

水平翻转图像平铺的矩形。

Image image = new Bitmap("HouseAndTree.gif");
TextureBrush tBrush = new TextureBrush(image);
Pen blackPen = new Pen(Color.Black);
tBrush.WrapMode = WrapMode.TileFlipX;
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
Dim image As New Bitmap("HouseAndTree.gif")
Dim tBrush As New TextureBrush(image)
Dim blackPen As New Pen(Color.Black)
tBrush.WrapMode = WrapMode.TileFlipX
e.Graphics.FillRectangle(tBrush, New Rectangle(0, 0, 200, 200))
e.Graphics.DrawRectangle(blackPen, New Rectangle(0, 0, 200, 200))

若要垂直时平铺翻转图像To flip an image vertically while tiling

  • 此示例使用相同 75 × 75 图像以填充 200 × 200 的矩形。This example uses the same 75×75 image to fill a 200×200 rectangle. 设置环绕模式为垂直翻转图像。The wrap mode is set to flip the image vertically.

    Image image = new Bitmap("HouseAndTree.gif");
    TextureBrush tBrush = new TextureBrush(image);
    Pen blackPen = new Pen(Color.Black);
    tBrush.WrapMode = WrapMode.TileFlipY;
    e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
    e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
    
    Dim image As New Bitmap("HouseAndTree.gif")
    Dim tBrush As New TextureBrush(image)
    Dim blackPen As New Pen(Color.Black)
    tBrush.WrapMode = WrapMode.TileFlipY
    e.Graphics.FillRectangle(tBrush, New Rectangle(0, 0, 200, 200))
    e.Graphics.DrawRectangle(blackPen, New Rectangle(0, 0, 200, 200))
    
    

平铺时水平和垂直翻转图像To flip an image horizontally and vertically while tiling

  • 此示例使用相同的 75 × 75 映像磁贴 200 × 200 的矩形。This example uses the same 75×75 image to tile a 200×200 rectangle. 自动换行模式设置为水平和垂直翻转图像。The wrap mode is set to flip the image both horizontally and vertically. 下图显示该矩形的映像的平铺。The following illustration shows how the rectangle is tiled by the image. 请注意当您从一个磁贴移动到下一个给定行中,水平翻转图像和当您从一个磁贴移动到下一个给定列中,垂直翻转图像。Note that as you move from one tile to the next in a given row, the image is flipped horizontally, and as you move from one tile to the next in a given column, the image is flipped vertically.

水平和垂直翻转图像平铺的矩形。

Image image = new Bitmap("HouseAndTree.gif");
TextureBrush tBrush = new TextureBrush(image);
Pen blackPen = new Pen(Color.Black);
tBrush.WrapMode = WrapMode.TileFlipXY;
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
Dim image As New Bitmap("HouseAndTree.gif")
Dim tBrush As New TextureBrush(image)
Dim blackPen As New Pen(Color.Black)
tBrush.WrapMode = WrapMode.TileFlipXY
e.Graphics.FillRectangle(tBrush, New Rectangle(0, 0, 200, 200))
e.Graphics.DrawRectangle(blackPen, New Rectangle(0, 0, 200, 200))

请参阅See also