첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ 부드러운 그래픽 그리기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Drawing.Text;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 이미지

        /// </summary>

        private Image image;

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            this.image = Image.FromFile("sample.bmp");

 

            #region 이벤트를 설정한다.

 

            Paint += Form_Paint;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        #region 폼 페인트시 처리하기 - Form_Paint(sender, e)

 

        /// <summary>

        /// 폼 페인트시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Form_Paint(object sender, PaintEventArgs e)

        {

            using(Font font = new Font("Times New Roman", 16))

            {

                int x = 20;

                int y = 20;

 

                e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;

 

                e.Graphics.DrawString("Without Smoothing", font, Brushes.Blue, x, y);

 

                y += 40;

 

                e.Graphics.DrawImage(this.image, x, y, 50, 50);

 

                y += 70;

 

                e.Graphics.DrawEllipse(Pens.Red, x, y, 100, 50);

 

                e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;

                e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                e.Graphics.InterpolationMode = InterpolationMode.High;

 

                x = 300;

                y = 20;

 

                e.Graphics.DrawString("With Smoothing", font, Brushes.Blue, x, y);

 

                y += 40;

 

                e.Graphics.DrawImage(this.image, x, y, 50, 50);

 

                y += 70;

 

                e.Graphics.DrawEllipse(Pens.Red, x, y, 100, 50);

            }

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요