texturebrush 平铺渲染_如何:在形状中平铺图像 - Windows Forms .NET Framework | Microsoft Docs...

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

03/30/2017

本文内容

正如可以将磁贴置于彼此旁边以涵盖楼层一样,可以将矩形图像放在相邻位置,以填充形状) (图块。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.

9507c97fde26d3695762f767c8a9a5ca.gif

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

0ac75f8030c9f47b2e4b6ebdcc04c788.gif

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.

a645ced3097021550cc3c9544b2a9652.gif

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.

2d7ba169fd2287c8f254377f7be7140e.gif

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值