共用方式為


如何使用影像鋪貼圖形

正如磁磚可以並排列放來覆蓋地板,矩形圖像也可以並排列放來填滿(拼貼)圖形。 若要填滿圖形的內部,請使用紋理刷具。 當您建構 TextureBrush 物件時,您傳遞給建構函式的其中一個引數是 Image 物件。 當您使用紋理筆刷繪製圖形的內部時,圖形會填滿此影像的重複復本。

TextureBrush 物件的包裝模式屬性會決定影像在矩形方格中重複時,影像導向的方式。 您可以將方格中的所有圖格設為相同的方向,也可以讓影像從一個網格線位置翻轉到下一個網格線。 翻轉可以是水平、垂直或兩者皆是。 下列範例展示不同類型翻轉的平鋪方式。

若要並排顯示影像

  • 此範例使用下列 75×75 影像來並排顯示 200×200 矩形。

The tile image that shows a red house and a tree.顯示紅色房屋和樹木的並排顯示影像。

  • 下圖插圖顯示矩形是如何以影像進行平鋪的。 請注意,所有磚的方向都相同;沒有翻轉。

A rectangle tiled with the image using the same orientation for all tiles.針對所有並排顯示使用相同的方向,以影像並排顯示的矩形。

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))

在並排顯示時水平翻轉影像

  • 這個範例使用相同的 75×75 影像來填滿 200×200 矩形。 環繞模式設定為水平翻轉影像。 下圖插圖顯示矩形是如何以影像進行平鋪的。 請注意,當您從給定的行中的一個磁磚移至下一個時,圖像會水平翻轉。

A rectangle tiled with the image 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))

在並排顯示時垂直翻轉影像

  • 這個範例使用相同的 75×75 影像來填滿 200×200 矩形。 環繞模式設定為垂直翻轉圖像。

    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))
    
    

在並排顯示時水平和垂直翻轉影像

  • 這個範例使用相同的 75×75 影像來並排顯示 200×200 矩形。 包裝模式設定為水準和垂直翻轉影像。 下圖展示影像如何填充矩形。 請注意,當您從某個圖格移至指定數據列中的下一個圖格時,影像會水準翻轉,當您從指定數據行中的一個磚移至下一個磚時,影像會垂直翻轉。

A rectangle tiled with the image flipped horizontally and 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))

另請參閱