■ ICanvas 인터페이스의 Rotate 메소드를 사용해 특정 위치를 기준으로 회전 변환을 하는 방법을 보여준다.
▶ GraphicsDrawable.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 |
namespace TestProject; /// <summary> /// 그래픽스 그리기 가능형 /// </summary> public class GraphicsDrawable : IDrawable { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 그리기 - Draw(canvas, dirtyRectangle) /// <summary> /// 그리기 /// </summary> /// <param name="canvas">캔버스</param> /// <param name="dirtyRectangle">더티 사각형</param> public void Draw(ICanvas canvas, RectF dirtyRectangle) { canvas.Rotate(45, dirtyRectangle.Center.X, dirtyRectangle.Center.Y); canvas.FillColor = Colors.Yellow; canvas.FillRectangle(dirtyRectangle); canvas.FontSize = 36; canvas.FontColor = Colors.Blue; canvas.FillColor = Colors.Blue; canvas.FillCircle(0, 0, 3); canvas.DrawString(".NET MAUI", 150, 150, HorizontalAlignment.Left); } #endregion } |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TestProject"> <ContentPage.Resources> <local:GraphicsDrawable x:Key="GraphicsDrawableKey" /> </ContentPage.Resources> <GraphicsView HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="350" HeightRequest="350" Drawable="{StaticResource GraphicsDrawableKey}" /> </ContentPage> |