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

### 平铺图像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))