■ ICanvas 인터페이스의 BlendMode 속성을 사용해 혼합 모드를 설정하는 방법을 보여준다.
▶ 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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) { PointF centerPoint = new PointF(dirtyRectangle.Center.X, dirtyRectangle.Center.Y); float radius = Math.Min(dirtyRectangle.Width, dirtyRectangle.Height) / 4; float distance = 0.8f * radius; PointF centerPoint1 = new PointF ( distance * (float)Math.Cos(9 * Math.PI / 6) + centerPoint.X, distance * (float)Math.Sin(9 * Math.PI / 6) + centerPoint.Y ); PointF centerPoint2 = new PointF ( distance * (float)Math.Cos(1 * Math.PI / 6) + centerPoint.X, distance * (float)Math.Sin(1 * Math.PI / 6) + centerPoint.Y ); PointF centerPoint3 = new PointF ( distance * (float)Math.Cos(5 * Math.PI / 6) + centerPoint.X, distance * (float)Math.Sin(5 * Math.PI / 6) + centerPoint.Y ); canvas.BlendMode = BlendMode.Multiply; canvas.FillColor = Colors.Cyan; canvas.FillCircle(centerPoint1, radius); canvas.FillColor = Colors.Magenta; canvas.FillCircle(centerPoint2, radius); canvas.FillColor = Colors.Yellow; canvas.FillCircle(centerPoint3, radius); } #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> |
※ 프리뷰 버전 테스트시, ICanvas 인터페이스 BlendMode 속성을 Multiply로 설정했으나 정상적으로 표시되지 않았다.