■ DrawingVisual 클래스를 사용해 라운드 사각형 이미지를 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 |
using System.Windows.Media; #region 라운드 사각형 드로잉 비주얼 객체 구하기 - GetRoundedRectangleDrawingVisual(width, height) /// <summary> /// 라운드 사각형 드로잉 비주얼 객체 구하기 /// </summary> /// <param name="width">너비</param> /// <param name="height">높이</param> /// <returns>라운드 사각형 드로잉 비주얼 객체</returns> public DrawingVisual GetRoundedRectangleDrawingVisual(double width, double height) { DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); double penWidth = 10d; drawingContext.DrawRoundedRectangle ( Brushes.Blue, new Pen(Brushes.Red, penWidth), new Rect(penWidth / 2d, penWidth / 2d, width - penWidth, height - penWidth), penWidth, penWidth ); drawingContext.Close(); return drawingVisual; } #endregion |