첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Drawing;
using System.Drawing.Imaging;
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 = Image.FromFile("sample.jpg");

            #region 이벤트를 설정한다.

            Load += Form_Load;

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            Image sourceImage = this.pictureBox.Image;

            int width  = sourceImage.Width;
            int height = sourceImage.Height;

            Bitmap bitmap = new Bitmap(width, height);

            using(Graphics graphics = Graphics.FromImage(bitmap))
            {
                Color[] colorArray =
                {
                    Color.Red,
                    Color.OrangeRed,
                    Color.Yellow,
                    Color.Green,
                    Color.Blue,
                    Color.Indigo,
                    Color.Fuchsia
                };

                const float scale = 1.0f;

                for(int i = 0; i < colorArray.Length; i++)
                {
                    float red   = colorArray[i].R / 255f * scale;
                    float green = colorArray[i].G / 255f * scale;
                    float blue  = colorArray[i].B / 255f * scale;

                    ColorMatrix colorMatrix = new ColorMatrix
                    (
                        new float[][]
                        {
                            new float[] { red, 0    , 0   , 0, 0 },
                            new float[] { 0  , green, 0   , 0, 0 },
                            new float[] { 0  , 0    , blue, 0, 0 },
                            new float[] { 0  , 0    , 0   , 1, 0 },
                            new float[] { 0  , 0    , 0   , 0, 1 },
                        }
                    );

                    ImageAttributes imageAttributes = new ImageAttributes();

                    imageAttributes.SetColorMatrix(colorMatrix);

                    int x = (int)(i * sourceImage.Width / colorArray.Length);

                    Point[] pointArray =
                    {
                        new Point(x, 0),
                        new Point(width, 0),
                        new Point(x, height),
                    };

                    Rectangle rectangle = new Rectangle(x, 0, width - x, height);

                    graphics.DrawImage(sourceImage, pointArray, rectangle, GraphicsUnit.Pixel, imageAttributes);
                }
            }

            this.pictureBox.Image = bitmap;
        }

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

댓글을 달아 주세요