이 예제에서는 TileBrush의 바둑판 크기를 설정하는 방법을 보여 줍니다. TileBrush는 현재 그리고 있는 영역을 완전히 채우는 단일 바둑판을 생성합니다. Viewport 및 ViewportUnits 속성을 설정하면 이 동작을 재정의할 수 있습니다.
Viewport 속성은 TileBrush의 바둑판 크기를 지정합니다. 기본적으로 Viewport 속성의 값은 그리고 있는 영역의 크기에 상대적입니다. Viewport 속성에서 절대적인 바둑판 크기를 지정하도록 하려면 ViewportUnits 속성을 Absolute로 설정하십시오.
예제
다음 예제에서는 TileBrush 형식의 ImageBrush를 사용하여 사각형을 바둑판으로 그립니다. 또한 각 바둑판을 출력 영역(사각형)의 가로 50퍼센트, 세로 50퍼센트로 설정합니다. 그 결과 사각형에 네 개의 이미지가 그려집니다.
다음 그림에서는 이 예제의 출력을 보여 줍니다.
'
' Create an ImageBrush and set the size of each
' tile to 50% by 50% of the area being painted.
'
Dim relativeTileSizeImageBrush As New ImageBrush()
relativeTileSizeImageBrush.ImageSource = New BitmapImage(New Uri("sampleImages\cherries_larger.jpg", UriKind.Relative))
relativeTileSizeImageBrush.TileMode = TileMode.Tile
' Specify the size of the base tile.
' By default, the size of the Viewport is
' relative to the area being painted,
' so a value of 0.5 indicates 50% of the output
' area.
relativeTileSizeImageBrush.Viewport = New Rect(0, 0, 0.5, 0.5)
' Create a rectangle and paint it with the ImageBrush.
Dim relativeTileSizeExampleRectangle As New Rectangle()
With relativeTileSizeExampleRectangle
.Width = 200
.Height = 150
.Stroke = Brushes.LimeGreen
.StrokeThickness = 1
.Fill = relativeTileSizeImageBrush
End With
//
// Create an ImageBrush and set the size of each
// tile to 50% by 50% of the area being painted.
//
ImageBrush relativeTileSizeImageBrush = new ImageBrush();
relativeTileSizeImageBrush.ImageSource =
new BitmapImage(new Uri(@"sampleImages\cherries_larger.jpg", UriKind.Relative));
relativeTileSizeImageBrush.TileMode = TileMode.Tile;
// Specify the size of the base tile.
// By default, the size of the Viewport is
// relative to the area being painted,
// so a value of 0.5 indicates 50% of the output
// area.
relativeTileSizeImageBrush.Viewport = new Rect(0, 0, 0.5, 0.5);
// Create a rectangle and paint it with the ImageBrush.
Rectangle relativeTileSizeExampleRectangle = new Rectangle();
relativeTileSizeExampleRectangle.Width = 200;
relativeTileSizeExampleRectangle.Height = 150;
relativeTileSizeExampleRectangle.Stroke = Brushes.LimeGreen;
relativeTileSizeExampleRectangle.StrokeThickness = 1;
relativeTileSizeExampleRectangle.Fill = relativeTileSizeImageBrush;
<!-- The ImageBrush's tiles are set to 50% by 50% of the output area. -->
<Rectangle
Width="200" Height="150"
Stroke="LimeGreen" StrokeThickness="1">
<Rectangle.Fill>
<ImageBrush
Viewport="0,0,0.5,0.5"
TileMode="Tile"
ImageSource="sampleImages\cherries_larger.jpg" />
</Rectangle.Fill>
</Rectangle>
다음 예제에서는 ImageBrush를 만들고 Viewport를 0,0,25,25로, ViewportUnits를 Absolute로 설정한 다음 이를 사용하여 다른 사각형을 그립니다. 그 결과로 가로 25 픽셀, 세로 25 픽셀인 바둑판이 브러시를 통해 만들어집니다.
다음 그림에서는 이 예제의 출력을 보여 줍니다.
'
' Create an ImageBrush and set the size of each
' tile to 25 by 25 pixels.
'
Dim absoluteTileSizeImageBrush As New ImageBrush()
absoluteTileSizeImageBrush.ImageSource = New BitmapImage(New Uri("sampleImages\cherries_larger.jpg", UriKind.Relative))
absoluteTileSizeImageBrush.TileMode = TileMode.Tile
' Specify that the Viewport is to be interpreted as
' an absolute value.
absoluteTileSizeImageBrush.ViewportUnits = BrushMappingMode.Absolute
' Set the size of the base tile. Had we left ViewportUnits set
' to RelativeToBoundingBox (the default value),
' each tile would be 25 times the size of the area being
' painted. Because ViewportUnits is set to Absolute,
' the following line creates tiles that are 25 by 25 pixels.
absoluteTileSizeImageBrush.Viewport = New Rect(0, 0, 25, 25)
' Create a rectangle and paint it with the ImageBrush.
Dim absoluteTileSizeExampleRectangle As New Rectangle()
With absoluteTileSizeExampleRectangle
.Width = 200
.Height = 150
.Stroke = Brushes.LimeGreen
.StrokeThickness = 1
.Fill = absoluteTileSizeImageBrush
End With
//
// Create an ImageBrush and set the size of each
// tile to 25 by 25 pixels.
//
ImageBrush absoluteTileSizeImageBrush = new ImageBrush();
absoluteTileSizeImageBrush.ImageSource =
new BitmapImage(new Uri(@"sampleImages\cherries_larger.jpg", UriKind.Relative));
absoluteTileSizeImageBrush.TileMode = TileMode.Tile;
// Specify that the Viewport is to be interpreted as
// an absolute value.
absoluteTileSizeImageBrush.ViewportUnits = BrushMappingMode.Absolute;
// Set the size of the base tile. Had we left ViewportUnits set
// to RelativeToBoundingBox (the default value),
// each tile would be 25 times the size of the area being
// painted. Because ViewportUnits is set to Absolute,
// the following line creates tiles that are 25 by 25 pixels.
absoluteTileSizeImageBrush.Viewport = new Rect(0, 0, 25, 25);
// Create a rectangle and paint it with the ImageBrush.
Rectangle absoluteTileSizeExampleRectangle = new Rectangle();
absoluteTileSizeExampleRectangle.Width = 200;
absoluteTileSizeExampleRectangle.Height = 150;
absoluteTileSizeExampleRectangle.Stroke = Brushes.LimeGreen;
absoluteTileSizeExampleRectangle.StrokeThickness = 1;
absoluteTileSizeExampleRectangle.Fill = absoluteTileSizeImageBrush;
<!-- The ImageBrush's tiles are set to 25 by 25 pixels. -->
<Rectangle
Width="200" Height="150"
Stroke="LimeGreen" StrokeThickness="1">
<Rectangle.Fill>
<ImageBrush
Viewport="0,0,25,25"
ViewportUnits="Absolute"
TileMode="Tile"
ImageSource="sampleImages\cherries_larger.jpg" />
</Rectangle.Fill>
</Rectangle>
앞의 예제들은 보다 큰 샘플의 일부입니다. 전체 샘플을 보려면 ImageBrush 샘플을 참조하십시오.
이 예제에서는 ImageBrush 클래스를 사용하지만 Viewport 및 ViewportUnits 속성은 다른 TileBrush 개체, 즉 DrawingBrush 및 VisualBrush에 대해서도 동일하게 동작합니다. ImageBrush 및 다른 TileBrush 개체에 대한 자세한 내용은 이미지, 그림 및 시각적 표시로 그리기를 참조하십시오.
참고 항목
작업
방법: TileBrush로 다른 바둑판식 배열 패턴 만들기