첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

using System.Drawing;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            this.pictureBox.Image = GetTransparentBitmap(this.pictureBox.Width - 10, this.pictureBox.Height - 10);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 투명 비트맵 구하기 - GetTransparentBitmap(width, height)

        /// <summary>
        /// 투명 비트맵 구하기
        /// </summary>
        /// <param name="width">너비</param>
        /// <param name="height">높이</param>
        /// <returns></returns>
        private Bitmap GetTransparentBitmap(int width, int height)
        {
           Bitmap bitmap = new Bitmap(width, height);

           using(Graphics graphics = Graphics.FromImage(bitmap))
           {
               graphics.Clear(Color.Transparent);

               using(Pen pen = new Pen(Color.RoyalBlue, 20))
               {
                    int ellipseWidth  = width  - (int)pen.Width;
                    int ellipseHeight = height - (int)pen.Width;

                    ellipseWidth  = ellipseWidth  < 0 ? 1 : ellipseWidth;
                    ellipseHeight = ellipseHeight < 0 ? 1 : ellipseHeight;

                    int x = (width  - ellipseWidth ) / 2;
                    int y = (height - ellipseHeight) / 2;

                    graphics.DrawEllipse(pen, x, y, ellipseWidth, ellipseHeight);
               }
            }

            return bitmap;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요