■ CanvasControl 클래스의 Draw 이벤트를 사용해 그림자 효과를 그리는 방법을 보여준다.
※ 비주얼 스튜디오에서 TestProject(Unpackaged) 모드로 빌드한다.
※ TestProject.csproj 프로젝트 파일에서 WindowsPackageType 태그를 None으로 추가했다.
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?> <Page x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mgcux="using:Microsoft.Graphics.Canvas.UI.Xaml" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" FontFamily="나눔고딕코딩" FontSize="16"> <mgcux:CanvasControl Name="canvasControl" Margin="50" /> </Page> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
using System.Numerics; using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Geometry; using Microsoft.Graphics.Canvas.Effects; using Microsoft.Graphics.Canvas.UI.Xaml; using Microsoft.UI; using Microsoft.UI.Xaml.Controls; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public sealed partial class MainPage : Page { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.canvasControl.Draw += canvasControl_Draw; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 캔버스 컨트롤 그리기 - canvasControl_Draw(canvasControl, e) /// <summary> /// 캔버스 컨트롤 그리기 /// </summary> /// <param name="canvasControl">캔버스 컨트롤</param> /// <param name="e">이벤트 인자</param> private void canvasControl_Draw(CanvasControl canvasControl, CanvasDrawEventArgs e) { using(CanvasDrawingSession canvasDrawingSession1 = e.DrawingSession) { CanvasGeometry canvasGeometry1 = CanvasGeometry.CreatePolygon ( canvasControl, [ new Vector2( 10, 110), new Vector2( 60, 10), new Vector2(110, 110), new Vector2(105, 110), new Vector2( 60, 18), new Vector2( 15, 110), new Vector2( 10, 110) ] ); CanvasCommandList canvasCommandList1 = new CanvasCommandList(canvasControl); using(CanvasDrawingSession CanvasDrawingSession2 = canvasCommandList1.CreateDrawingSession()) { CanvasDrawingSession2.DrawGeometry(canvasGeometry1, Colors.DarkRed, 2); CanvasDrawingSession2.FillGeometry(canvasGeometry1, Colors.Red); } GaussianBlurEffect gaussianBlurEffect1 = new GaussianBlurEffect { Source = canvasCommandList1, BlurAmount = 10f }; canvasDrawingSession1.DrawImage(gaussianBlurEffect1); canvasDrawingSession1.DrawGeometry(canvasGeometry1, Colors.DarkRed, 2); canvasDrawingSession1.FillGeometry(canvasGeometry1, Colors.Red); CanvasGeometry canvasGeometry2 = CanvasGeometry.CreatePolygon ( canvasControl, [ new Vector2(160, 105), new Vector2(260, 105), new Vector2(260, 10), new Vector2(265, 10), new Vector2(265, 110), new Vector2(160, 110), new Vector2(160, 105) ] ); CanvasCommandList canvasCommandList2 = new CanvasCommandList(canvasControl); using(CanvasDrawingSession canvasDrawingSession3 = canvasCommandList2.CreateDrawingSession()) { canvasDrawingSession3.DrawGeometry(canvasGeometry2, Colors.DarkGreen, 2); canvasDrawingSession3.FillGeometry(canvasGeometry2, Colors.Green); } GaussianBlurEffect gaussianBlurEffect2 = new GaussianBlurEffect { Source = canvasCommandList2, BlurAmount = 10f }; canvasDrawingSession1.DrawImage(gaussianBlurEffect2); canvasDrawingSession1.DrawGeometry(canvasGeometry2, Colors.DarkGreen, 2); canvasDrawingSession1.FillGeometry(canvasGeometry2, Colors.Green); } } #endregion } |