첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ ImageItem.cs

using System.Drawing;

namespace TestProject
{
    /// <summary>
    /// 이미지 항목
    /// </summary>
    public class ImageItem
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region Field

        /// <summary>
        /// 왼쪽 이미지
        /// </summary>
        public Image LeftImage = null;

        /// <summary>
        /// 오른쪽 이미지
        /// </summary>
        public Image RightImage = null;

        /// <summary>
        /// X 좌표
        /// </summary>
        public int X = 0;

        /// <summary>
        /// Y 좌표
        /// </summary>
        public int Y = 0;

        /// <summary>
        /// 스케일
        /// </summary>
        public float Scale = 0;

        /// <summary>
        /// 깊이
        /// </summary>
        public int Depth = 0;

        #endregion
    }
}

 

▶ BackgroundForm.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 배경 폼
    /// </summary>
    public partial class BackgroundForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 로드 여부
        /// </summary>
        private bool isLoaded = true;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - BackgroundForm()

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

            #region 이벤트를 설정한다.

            Activated += Form_Activated;

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 배경 이미지 설정하기 - SetBackgroundImage(imageList)

        /// <summary>
        /// 배경 이미지 설정하기
        /// </summary>
        /// <param name="imageList">이미지 리스트</param>
        public void SetBackgroundImage(List<Image> imageList)
        {
            if(this.isLoaded)
            {
                int i = 0;
                int x = 0;
                int y = 0;

                foreach(Image image in imageList)
                {
                    Button button = new Button();

                    x = 5 + (i % 8) * 100;
                    y = 5 + (int)(i / 8) * 100;

                    i++;

                    button.Location        = new Point(x, y);
                    button.Size            = new Size(90, 90);
                    button.BackgroundImage = image;
                    button.Visible         = true;

                    button.Click += button_Click;

                    Controls.Add(button);
                }

                int height = 140 + ((i - 1) / 8 * 100);

                if(i > 8)
                {
                    i = 8;
                }

                int width = 20 + i * 100;

                Size = new Size(width, height);

                this.isLoaded = false;
            }
        }

        #endregion

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

        #region 폼 활성화시 처리하기 - Form_Activated(sender, e)

        /// <summary>
        /// 폼 활성화시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Activated(object sender, EventArgs e)
        {
            BackgroundImage = null;
        }

        #endregion
        #region 버튼 클릭시 처리하기 - button_Click(sender, e)

        /// <summary>
        /// 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void button_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            BackgroundImage = button.BackgroundImage;

            Close();
        }

        #endregion
    }
}

 

▶ MainForm.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Windows.Forms;

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

        #region Field

        /// <summary>
        /// 배경 폼
        /// </summary>
        private BackgroundForm backgroundForm = new BackgroundForm();

        /// <summary>
        /// 이미지 타입 리스트
        /// </summary>
        private List<string> imageTypeList = new List<string>(new string[] { "*.gif", "*.png", "*.jpg", "*.bmp" });

        /// <summary>
        /// 워드 리스트
        /// </summary>
        private List<string> wordList;

        /// <summary>
        /// 배경 이미지 리스트
        /// </summary>
        private List<Image> backgroundImageList = new List<Image>();

        /// <summary>
        /// 스마일 이미지 리스트
        /// </summary>
        private List<Image> smileImageList =new List<Image>();

        /// <summary>
        /// 도형 이미지 리스트
        /// </summary>
        private List<Image> shapeImageList = new List<Image>();

        /// <summary>
        /// 왼쪽 이미지 리스트
        /// </summary>
        private List<Image> d3LeftImageList = new List<Image>();

        /// <summary>
        /// 오른쪽 이미지 리스트
        /// </summary>
        private List<Image> d3RightImageList = new List<Image>();

        /// <summary>
        /// 이미지 항목
        /// </summary>
        private ImageItem imageItem;

        /// <summary>
        /// 이미지 항목 리스트
        /// </summary>
        private List<ImageItem> imageItemList;

        /// <summary>
        /// 왼쪽 비트맵
        /// </summary>
        private Bitmap leftBitmap;
        
        /// <summary>
        /// 오른쪽 비트맵
        /// </summary>
        private Bitmap rightBitmap;

        /// <summary>
        /// 난수 발생기
        /// </summary>
        private Random random = new Random();

        /// <summary>
        /// X 변경
        /// </summary>
        private int xChange = 1;

        /// <summary>
        /// 타이머 시작 여부
        /// </summary>
        private bool startTimer = true;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            SetControlSize();

            LoadData();

            this.backgroundImagePictureBox.BackgroundImage = this.backgroundImageList[this.random.Next(this.backgroundImageList.Count)];

            #region 이벤트를 설정한다.

            ResizeEnd   += Form_ResizeEnd;
            SizeChanged += Form_SizeChanged;

            // 메뉴
            this.saveMenuItem.Click   += saveMenuItem_Click;
            this.saveAsMenuItem.Click += saveAsMenuItem_Click;
            this.exitMenuItem.Click   += exitMenuItem_Click;

            // 텍스트
            this.showTextCheckBox.CheckedChanged   += showTextCheckBox_CheckedChanged;
            this.fontTextBox.Click                 += fontTextBox_Click;
            this.textColorLabel.Click              += textColorLabel_Click;
            this.shadowColorLabel.Click            += shadowColorLabel_Click;
            this.randomFillCheckBox.CheckedChanged += randomFillCheckBox_CheckedChanged;

            // 객체
            this.serialCheckBox.CheckedChanged += serialCheckBox_CheckedChanged;

            // 배경
            this.backgroundColorRadioButton.CheckedChanged += backgroundColorRadioButton_CheckedChanged;
            this.backgroundColorLabel.Click                += backgroundColorLabel_Click;
            this.backgroundImagePictureBox.Click           += backgroundImagePictureBox_Click;

            // 3D 뷰
            this.parallelViewRadioButton.CheckedChanged += parallelViewRadioButton_CheckedChanged;

            // 타이머
            this.timerCheckBox.CheckedChanged    += timerCheckBox_CheckedChanged;
            this.delayNumericUpDown.ValueChanged += delayNumericUpDown_ValueChanged;

            // 기타
            this.guildeLineColorLabel.Click += guildeLineColorLabel_Click;

            // 실행
            this.runButton.Click += runButton_Click;

            // 불릿
            this.leftBulletPictureBox.SizeChanged += leftBulletPictureBox_SizeChanged;

            // 왼쪽 이미지
            this.leftImagePictureBox.BackColorChanged       += leftImagePictureBox_BackColorChanged;
            this.leftImagePictureBox.BackgroundImageChanged += leftImagePictureBox_BackgroundImageChanged;

            // 왼쪽 애니메이션 레이블
            this.leftAnimationLabel.TextChanged += leftAnimationLabel_TextChanged;

            // 타이머
            this.timer.Tick          += timer_Tick;
            this.animationTimer.Tick += animationTimer_Tick;

            #endregion
        }

        #endregion

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

        #region 폼 크기 변경 종료시 처리하기 - Form_ResizeEnd(sender, e)

        /// <summary>
        /// 폼 크기 변경 종료시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_ResizeEnd(object sender, EventArgs e)
        {
            if(Width < 600)
            {
                Width = 600;
            }

            if(Height < 400)
            {
                Height = 400;
            }
        }

        #endregion
        #region 폼 크기 변경시 처리하기 - Form_SizeChanged(sender, e)

        /// <summary>
        /// 폼 크기 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_SizeChanged(object sender, EventArgs e)
        {
            SetControlSize();
        }

        #endregion

        #region 저장하기 메뉴 항목 클릭시 처리하기 - saveMenuItem_Click(sender, e)

        /// <summary>
        /// 저장하기 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void saveMenuItem_Click(object sender, EventArgs e)
        {
            SaveImage();
        }

        #endregion
        #region 다른 이름으로 저장하기 메뉴 항목 클릭시 처리하기 - saveAsMenuItem_Click(sender, e)

        /// <summary>
        /// 다른 이름으로 저장하기 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void saveAsMenuItem_Click(object sender, EventArgs e)
        {
            this.saveFileDialog.FileName         = (this.parallelViewRadioButton.Checked ? "Parallel" : "Cross") + DateTime.Now.ToString("yyyyMMMdd_hhmmss");
            this.saveFileDialog.Filter           = "PNG|*.png|JPG|*.jpg";
            this.saveFileDialog.RestoreDirectory = true;

            if(this.saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                SaveImage(this.saveFileDialog.FileName, this.saveFileDialog.FilterIndex);
            }
        }

        #endregion
        #region 종료 메뉴 항목 클릭시 처리하기 - exitMenuItem_Click(sender, e)

        /// <summary>
        /// 종료 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void exitMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        #endregion

        #region 텍스트 표시 체크 박스 체크 변경시 처리하기 - showTextCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 텍스트 표시 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void showTextCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.showShadowCheckBox.Enabled = this.showTextCheckBox.Checked;
        }

        #endregion
        #region 폰트 텍스트 박스 클릭시 처리하기 - fontTextBox_Click(sender, e)

        /// <summary>
        /// 폰트 텍스트 박스 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void fontTextBox_Click(object sender, EventArgs e)
        {
            try
            {
                FontStyle fontStyle = FontStyle.Regular;

                if(this.boldCheckBox.Checked)
                {
                    fontStyle = FontStyle.Bold;
                }

                if(this.italicCheckBox.Checked)
                {
                    fontStyle = fontStyle | FontStyle.Italic;
                }

                this.fontDialog.Font = new Font(this.fontTextBox.Text, (float)this.fontSizeNumericUpDown.Value, fontStyle);

                if(this.fontDialog.ShowDialog() == DialogResult.OK)
                {
                    this.fontTextBox.Text = this.fontDialog.Font.Name;

                    this.fontSizeNumericUpDown.Value = (decimal)this.fontDialog.Font.Size;

                    this.italicCheckBox.Checked = this.fontDialog.Font.Italic;
                    this.boldCheckBox.Checked   = this.fontDialog.Font.Bold;
                }
            }
            catch(Exception exception)
            {
                MessageBox.Show(this, exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion
        #region 텍스트 색상 레이블 클릭시 처리하기 - textColorLabel_Click(sender, e)

        /// <summary>
        /// 텍스트 색상 레이블 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void textColorLabel_Click(object sender, EventArgs e)
        {
            SetColor(this.textColorLabel);
        }

        #endregion
        #region 그림자 색상 레이블 클릭시 처리하기 - shadowColorLabel_Click(sender, e)

        /// <summary>
        /// 그림자 색상 레이블 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void shadowColorLabel_Click(object sender, EventArgs e)
        {
            SetColor(this.shadowColorLabel);
        }

        #endregion
        #region 랜덤 채우기 체크 박스 체크 변경시 처리하기 - randomFillCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 랜덤 채우기 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void randomFillCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.moreColorCheckBox.Enabled = this.randomFillCheckBox.Checked;
        }

        #endregion

        #region 시리얼 체크 박스 체크 변경시 처리하기 - serialCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 시리얼 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void serialCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.serialAroungCheckBox.Enabled = this.serialCheckBox.Checked;
        }

        #endregion

        #region 배경 색상 라디오 버튼 체크 변경시 처리하기 - backgroundColorRadioButton_CheckedChanged(sender, e)

        /// <summary>
        /// 배경 색상 라디오 버튼 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void backgroundColorRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.leftImagePictureBox.BackgroundImage = null;

            if(!this.backgroundColorRadioButton.Checked)
            {
                this.leftImagePictureBox.BackgroundImage = this.backgroundImagePictureBox.BackgroundImage;
            }
        }

        #endregion
        #region 배경 색상 레이블 클릭시 처리하기 - backgroundColorLabel_Click(sender, e)

        /// <summary>
        /// 배경 색상 레이블 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void backgroundColorLabel_Click(object sender, EventArgs e)
        {
            SetColor(this.backgroundColorLabel);
        }

        #endregion
        #region 배경 이미지 픽처 박스 클릭시 처리하기 - backgroundImagePictureBox_Click(sender, e)

        /// <summary>
        /// 배경 이미지 픽처 박스 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void backgroundImagePictureBox_Click(object sender, EventArgs e)
        {
            this.backgroundForm.SetBackgroundImage(this.backgroundImageList);

            this.backgroundForm.ShowDialog();

            if(this.backgroundForm.BackgroundImage != null)
            {
                this.backgroundImagePictureBox.BackgroundImage = this.backgroundForm.BackgroundImage;
            }

            this.backgroundImageRadioButton.Checked = true;

            this.leftImagePictureBox.BackgroundImage = this.backgroundImagePictureBox.BackgroundImage;
        }

        #endregion

        #region 평행 뷰 라디오 버튼 체크 변경시 처리하기 - parallelViewRadioButton_CheckedChanged(sender, e)

        /// <summary>
        /// 평행 뷰 라디오 버튼 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void parallelViewRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            SetView();
        }

        #endregion

        #region 타이머 체크 박스 체크 변경시 처리하기 - timerCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 타이머 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void timerCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.delayNumericUpDown.Enabled = this.timerCheckBox.Checked;

            this.timer.Enabled = this.timerCheckBox.Checked;
        }

        #endregion
        #region 지연 숫자 UP/DOWN 값 변경시 처리하기 - delayNumericUpDown_ValueChanged(sender, e)

        /// <summary>
        /// 지연 숫자 UP/DOWN 값 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void delayNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            this.timer.Interval = (int)this.delayNumericUpDown.Value * 1000;
        }

        #endregion

        #region 안내선 색상 레이블 클릭시 처리하기 - guildeLineColorLabel_Click(sender, e)

        /// <summary>
        /// 안내선 색상 레이블 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void guildeLineColorLabel_Click(object sender, EventArgs e)
        {
            SetColor(this.guildeLineColorLabel);
        }

        #endregion

        #region 실행 버튼 클릭시 처리하기 - runButton_Click(sender, e)

        /// <summary>
        /// 실행 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void runButton_Click(object sender, EventArgs e)
        {
            this.runButton.Enabled = false;

            Application.DoEvents();

            CreateImage();
            
            this.runButton.Enabled = true;
        }

        #endregion

        #region 왼쪽 불릿 픽처 박스 크기 변경시 처리하기 - leftBulletPictureBox_SizeChanged(sender, e)

        /// <summary>
        /// 왼쪽 불릿 픽처 박스 크기 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void leftBulletPictureBox_SizeChanged(object sender, EventArgs e)
        {
            this.rightBulletPictureBox.Image = this.leftBulletPictureBox.Image;
        }

        #endregion

        #region 왼쪽 이미지 픽처 박스 배경 색상 변경시 처리하기 - leftImagePictureBox_BackColorChanged(sender, e)

        /// <summary>
        ///왼쪽 이미지 픽처 박스 배경 색상 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void leftImagePictureBox_BackColorChanged(object sender, EventArgs e)
        {
            this.rightImagePictureBox.BackColor = this.leftImagePictureBox.BackColor;
        }

        #endregion
        #region 왼쪽 이미지 픽처 박스 배경 이미지 변경시 처리하기 - leftImagePictureBox_BackgroundImageChanged(sender, e)

        /// <summary>
        /// 왼쪽 이미지 픽처 박스 배경 이미지 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void leftImagePictureBox_BackgroundImageChanged(object sender, EventArgs e)
        {
            this.rightImagePictureBox.BackgroundImage = this.leftImagePictureBox.BackgroundImage;
        }

        #endregion

        #region 왼쪽 애니메이션 레이블 텍스트 변경시 처리하기 - leftAnimationLabel_TextChanged(sender, e)

        /// <summary>
        /// 왼쪽 애니메이션 레이블 텍스트 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void leftAnimationLabel_TextChanged(object sender, EventArgs e)
        {
            this.rightAnimationLabel.Text = this.leftAnimationLabel.Text;
        }

        #endregion

        #region 타이머 틱 처리하기 - timer_Tick(sender, e)

        /// <summary>
        /// 타이머 틱 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void timer_Tick(object sender, EventArgs e)
        {
            this.runButton.Enabled = false;

            CreateImage();

            this.runButton.Enabled = true;
        }

        #endregion
        #region 애니메이션 타이머 틱 처리하기 - animationTimer_Tick(sender, e)

        /// <summary>
        /// 애니메이션 타이머 틱 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void animationTimer_Tick(object sender, EventArgs e)
        {
            this.rightAnimationLabel.Size = new Size(this.rightAnimationLabel.Size.Width + this.xChange, this.rightAnimationLabel.Size.Height);

            if(this.rightAnimationLabel.Width > this.leftAnimationLabel.Width + 2 || this.rightAnimationLabel.Width < this.leftAnimationLabel.Width - this.serialDepthTrackBar.Value - 5)
            {
                this.xChange *= -1;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 컨트롤 크기 설정하기 - SetControlSize()

        /// <summary>
        /// 컨트롤 크기 설정하기
        /// </summary>
        private void SetControlSize()
        {
            int imagePictureBoxWidth = (this.rightPanel.Size.Width - 20) / 2;

            this.leftImagePictureBox.Width = imagePictureBoxWidth;
            this.rightImagePictureBox.Size = this.leftImagePictureBox.Size;

            int animationLabelTop = this.leftImagePictureBox.Top + this.leftImagePictureBox.Height - 20;

            this.backgroundAnimationLabel.Top = animationLabelTop;
            this.leftAnimationLabel.Top       = animationLabelTop;
            this.rightAnimationLabel.Top      = animationLabelTop;

            this.leftAnimationLabel.Width  = imagePictureBoxWidth;
            this.rightAnimationLabel.Width = imagePictureBoxWidth;

            this.backgroundAnimationLabel.Width = imagePictureBoxWidth * 3;

            this.leftAnimationLabel.Left  = this.leftImagePictureBox.Left;
            this.rightAnimationLabel.Left = this.rightImagePictureBox.Left;

            this.leftBulletPictureBox.Left  = this.leftPanel.Width + this.leftImagePictureBox.Left  + imagePictureBoxWidth / 2;
            this.rightBulletPictureBox.Left = this.leftPanel.Width + this.rightImagePictureBox.Left + imagePictureBoxWidth / 2;

            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(Application.StartupPath + "\\Save\\");

                if(!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }
            }
            catch(Exception exception)
            {
                MessageBox.Show(this, exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion
        #region 파일 로드하기 - LoadFile(directory, leftImageList, rightImageList)

        /// <summary>
        /// 파일 로드하기
        /// </summary>
        /// <param name="directory">디렉토리</param>
        /// <param name="leftImageList">왼쪽 이미지 리스트</param>
        /// <param name="rightImageList">오른쪽 이미지 리스트</param>
        private void LoadFile(string directory, List<Image> leftImageList, List<Image> rightImageList)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(Application.StartupPath +"\\" + directory);

            if(directoryInfo.Exists)
            {
                foreach(string imageType in this.imageTypeList)
                {
                    foreach(FileInfo fileInfo in directoryInfo.GetFiles(imageType))
                    {
                        try
                        {
                            if(rightImageList != null)
                            {
                                Image rightImage = Image.FromFile(fileInfo.FullName + ".right");

                                rightImageList.Add(rightImage);
                            }

                            Image leftImage = Image.FromFile(fileInfo.FullName);

                            leftImageList.Add(leftImage);
                        }
                        catch(OutOfMemoryException)
                        {
                            continue;
                        }
                    }
                }
            }

        }

        #endregion
        #region 데이터 로드하기 - LoadData()

        /// <summary>
        /// 데이터 로드하기
        /// </summary>
        private void LoadData()
        {
            LoadFile("Image\\BackgroundImage", this.backgroundImageList, null                 );
            LoadFile("Image\\SmileImage"     , this.smileImageList     , null                 );
            LoadFile("Image\\ShapeImage"     , this.shapeImageList     , null                 );
            LoadFile("Image\\3DImage"        , this.d3LeftImageList    , this.d3RightImageList);

            this.wordList = new List<string>(new string[] { "I", "You", "He", "She", "We", "They" });

            this.wordList.AddRange(new string[] { "My", "Your", "His", "Her", "Our", "Their" });
            this.wordList.AddRange(new string[] { "Happy", "Merry", "Welcome", "Love", "Best", "Wishes", "Hate" });
            this.wordList.AddRange(new string[] { "Day", "Month", "Year", "Century", "Century", "Century" });
            this.wordList.AddRange(new string[] { "New", "Old", "After", "Befor", "Next", "Pre", "Last", "Next" });
            this.wordList.AddRange(new string[] { "Iran", "Persia", "Tehran", "Persian Gulf", "USA","Germany","France"});
            this.wordList.AddRange(new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" });
            this.wordList.AddRange(new string[] { "2006", "2007", "2008", "2009", "2010", "2011", "2012" });
        }

        #endregion

        #region 이미지 저장하기 - SaveImage(fileName, fileType)

        /// <summary>
        /// 이미지 저장하기
        /// </summary>
        /// <param name="fileName">파일명</param>
        /// <param name="fileType">파일 타입</param>
        private void SaveImage(string fileName, int fileType)
        {
            Bitmap leftBitmap;
            Bitmap rightBitmap;
            Bitmap textureBitmap;

            Bitmap fullBitmap = new Bitmap(this.leftImagePictureBox.Width * 2, this.leftImagePictureBox.Height);

            Graphics fullBitmapGraphics = Graphics.FromImage(fullBitmap);

            try
            {
                if(this.parallelViewRadioButton.Checked)
                {
                    leftBitmap  = new Bitmap(this.leftBitmap );
                    rightBitmap = new Bitmap(this.rightBitmap);
                }
                else
                {
                    leftBitmap  = new Bitmap(this.rightBitmap);
                    rightBitmap = new Bitmap(this.leftBitmap );
                }

                if(this.backgroundImageRadioButton.Checked)
                {
                    textureBitmap = new Bitmap(this.leftImagePictureBox.BackgroundImage);

                    for(int x = 0; x <= leftBitmap.Width / textureBitmap.Width; x++)
                    {
                        for(int y = 0; y <= leftBitmap.Height / textureBitmap.Height; y++)
                        {
                            fullBitmapGraphics.DrawImage
                            (
                                textureBitmap,
                                new Rectangle(textureBitmap.Width * x, textureBitmap.Height * y, textureBitmap.Width, textureBitmap.Height),
                                new Rectangle(0, 0, textureBitmap.Width, textureBitmap.Height),
                                GraphicsUnit.Pixel
                            );

                            fullBitmapGraphics.DrawImage
                            (
                                textureBitmap,
                                new Rectangle(leftBitmap.Width + textureBitmap.Width * x, textureBitmap.Height * y, textureBitmap.Width, textureBitmap.Height),
                                new Rectangle(0, 0, textureBitmap.Width, textureBitmap.Height),
                                GraphicsUnit.Pixel
                            );
                        }
                    }
                }
                else
                {
                    fullBitmapGraphics.FillRectangle
                    (
                        new SolidBrush(leftImagePictureBox.BackColor),
                        0,
                        0,
                        fullBitmap.Width,
                        fullBitmap.Height
                    );
                }

                fullBitmapGraphics.DrawImage
                (
                    leftBitmap,
                    new Rectangle(0, 0, leftBitmap.Width, leftBitmap.Height),
                    new Rectangle(0, 0, leftBitmap.Width, leftBitmap.Height),
                    GraphicsUnit.Pixel
                );

                fullBitmapGraphics.DrawImage
                (
                    rightBitmap,
                    new Rectangle(rightBitmap.Width, 0, rightBitmap.Width, rightBitmap.Height),
                    new Rectangle(0, 0, rightBitmap.Width, rightBitmap.Height),
                    GraphicsUnit.Pixel
                );

                fullBitmap.Save(fileName, (fileType == 1 ? ImageFormat.Png : ImageFormat.Jpeg));
            }
            catch(Exception exception)
            {
                MessageBox.Show(this, exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #endregion
        #region 이미지 저장하기 - SaveImage()

        /// <summary>
        /// 이미지 저장하기
        /// </summary>
        private void SaveImage()
        {
            SaveImage(Application.StartupPath + "\\Save\\" + (parallelViewRadioButton.Checked ? "Parallel" : "Cross") + DateTime.Now.ToString("yyyyMMMdd_hh-mm-ss") + ".png", 1);
        }

        #endregion

        #region 색상 설정하기 - SetColor(sourceLabel)

        /// <summary>
        /// 색상 설정하기
        /// </summary>
        /// <param name="sourceLabel">소스 레이블</param>
        private void SetColor(Label sourceLabel)
        {
            this.colorDialog.Color = sourceLabel.BackColor;

            if(this.colorDialog.ShowDialog() == DialogResult.OK)
            {
                sourceLabel.BackColor = colorDialog.Color;

                if(sourceLabel == this.backgroundColorLabel)
                {
                    this.backgroundColorRadioButton.Checked = true;

                    this.leftImagePictureBox.BackColor       = sourceLabel.BackColor;
                    this.leftImagePictureBox.BackgroundImage = null;
                }
            }
        }

        #endregion
        #region 뷰 설정하기 - SetView()

        /// <summary>
        /// 뷰 설정하기
        /// </summary>
        private void SetView()
        {
            if(this.parallelViewRadioButton.Checked)
            {
                this.leftImagePictureBox.SendToBack();

                this.leftBulletPictureBox.Image = Properties.Resources.bullet_07_june;

                this.leftAnimationLabel.Text = "Persian Gulf (Parallel)";
            }
            else
            {
                this.rightImagePictureBox.SendToBack();

                this.leftBulletPictureBox.Image = Properties.Resources.bullet_03;

                this.leftAnimationLabel.Text = "Persian Gulf (Cross eye)";
            }

            this.leftAnimationLabel.Left  = this.leftImagePictureBox.Left;
            this.rightAnimationLabel.Left = this.rightImagePictureBox.Left;
        }

        #endregion

        #region 그림 그리기 - DrawPicture(leftBitmapGraphics, rightBitmapGraphics, imageItem)

        /// <summary>
        /// 그림 그리기
        /// </summary>
        /// <param name="leftBitmapGraphics">왼쪽 비트맵 그래픽스</param>
        /// <param name="rightBitmapGraphics">오른쪽 비트맵 그래픽스</param>
        /// <param name="imageItem">이미지 항목</param>
        private void DrawPicture(Graphics leftBitmapGraphics, Graphics rightBitmapGraphics, ImageItem imageItem)
        {
            leftBitmapGraphics.DrawImage
            (
                imageItem.LeftImage,
                imageItem.X,
                imageItem.Y,
                imageItem.LeftImage.Width * imageItem.Scale,
                imageItem.LeftImage.Height *imageItem.Scale
            );

            rightBitmapGraphics.DrawImage
            (
                imageItem.RightImage,
                imageItem.X - imageItem.Depth,
                imageItem.Y,
                imageItem.RightImage.Width * imageItem.Scale,
                imageItem.RightImage.Height * imageItem.Scale
            );
        }

        #endregion
        #region 텍스트 그리기 - DrawText(text, leftBitmapGraphics, rightBitmapGraphics, x, y, depth, brush, font, shadow)

        /// <summary>
        /// 텍스트 그리기
        /// </summary>
        /// <param name="text">텍스트</param>
        /// <param name="leftBitmapGraphics">왼쪽 비트맵 그래픽스</param>
        /// <param name="rightBitmapGraphics">오른쪽 비트맵 그래픽스</param>
        /// <param name="x">X 좌표</param>
        /// <param name="y">Y 좌표</param>
        /// <param name="depth">깊이</param>
        /// <param name="brush">브러시</param>
        /// <param name="font">폰트</param>
        /// <param name="shadow">그림자</param>
        private void DrawText(string text, Graphics leftBitmapGraphics, Graphics rightBitmapGraphics, int x, int y, int depth, Brush brush, Font font, int shadow)
        {
            leftBitmapGraphics.DrawString(text, font, brush, x + shadow, y + shadow);

            rightBitmapGraphics.DrawString(text, font, brush, x + shadow - depth, y + shadow);
        }

        #endregion

        #region 이미지 생성하기 - CreateImage()

        /// <summary>
        /// 이미지 생성하기
        /// </summary>
        private void CreateImage()
        {
            if(this.startTimer)
            {
                this.animationTimer.Enabled = true;
            }

            this.imageItemList = new List<ImageItem>();

            this.leftBitmap = new Bitmap(this.leftImagePictureBox.Width, this.leftImagePictureBox.Height);

            Graphics leftBitmapGraphics = Graphics.FromImage(this.leftBitmap);

            leftBitmapGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            leftBitmapGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            this.rightBitmap = new Bitmap(this.rightImagePictureBox.Width, this.rightImagePictureBox.Height);

            Graphics rightBitmapGraphics = Graphics.FromImage(this.rightBitmap); ;

            rightBitmapGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            rightBitmapGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            this.leftImagePictureBox.BackgroundImage = null;

            if(this.randomizeCheckBox.Checked)
            {
                if(this.backgroundImageRadioButton.Checked)
                {
                    this.backgroundImagePictureBox.BackgroundImage = this.backgroundImageList[this.random.Next(this.backgroundImageList.Count)];

                    this.leftImagePictureBox.BackgroundImage = this.backgroundImagePictureBox.BackgroundImage;
                }
                else
                {
                    this.backgroundColorLabel.BackColor = Color.FromArgb(this.random.Next(255), this.random.Next(255), this.random.Next(255));
                }
            }
            else
            {
                if(this.backgroundImageRadioButton.Checked)
                {
                    this.leftImagePictureBox.BackgroundImage = this.backgroundImagePictureBox.BackgroundImage;
                }
            }

            this.leftImagePictureBox.BackColor = this.backgroundColorLabel.BackColor;

            FontStyle fontStyle = FontStyle.Regular;

            if(this.boldCheckBox.Checked)
            {
                fontStyle =  FontStyle.Bold;
            }

            if(this.italicCheckBox.Checked)
            {
                fontStyle = fontStyle | FontStyle.Italic;
            }

            Font  font = new Font(this.fontTextBox.Text.ToString(), (float)this.fontSizeNumericUpDown.Value, fontStyle, GraphicsUnit.Pixel);
            Brush brush;
            Brush shadowBrush;

            if(this.randomFillCheckBox.Checked)
            {
                for(int i = 1; i < fillTextNumericUpDown.Value * 5; i++)
                {
                    if(this.moreColorCheckBox.Checked && this.random.Next(3) != 1)
                    {
                        brush       = new SolidBrush(Color.FromArgb(this.random.Next(255), this.random.Next(255), this.random.Next(255)));
                        shadowBrush = new SolidBrush(Color.FromArgb(this.random.Next(255), this.random.Next(255), this.random.Next(255)));
                    }
                    else
                    {
                        brush       = new SolidBrush(this.textColorLabel.BackColor  );
                        shadowBrush = new SolidBrush(this.shadowColorLabel.BackColor);
                    }

                    string randomText = this.wordList[this.random.Next(this.wordList.Count)];

                    int x = this.random.Next(this.leftImagePictureBox.Width * 2) - this.leftImagePictureBox.Width;
                    int y = this.random.Next(this.leftImagePictureBox.Height);

                    DrawText(randomText, leftBitmapGraphics, rightBitmapGraphics, x, y, 0, shadowBrush, font, 4);
                    DrawText(randomText, leftBitmapGraphics, rightBitmapGraphics, x, y, 0, brush      , font, 0);
                }
            }

            int limitY = 0;

            if(this.serialCheckBox.Checked && this.serialAroungCheckBox.Checked)
            {
                limitY = (int)(50 + this.serialNumericUpDown.Value * 40);
            }

            if(this.smileCheckBox.Checked)
            {
                if(this.smileImageList.Count > 0)
                {
                    for(int i = 1; i <= this.smileNumericUpDown.Value; i++)
                    {
                        try
                        {
                            this.imageItem = new ImageItem();

                            this.imageItem.LeftImage  = this.smileImageList[this.random.Next(this.smileImageList.Count)];
                            this.imageItem.RightImage = this.imageItem.LeftImage;
                            this.imageItem.Depth      = this.random.Next(1, this.smileDepthTrackBar.Value / 2);
                            this.imageItem.Scale      = 1;
                            this.imageItem.X          = (this.random.Next(this.imageItem.Depth, this.leftImagePictureBox.Width - this.imageItem.LeftImage.Width - this.imageItem.Depth) % 
                                                        this.leftImagePictureBox.Width) + this.imageItem.Depth;
                            this.imageItem.Y          = this.random.Next(this.leftImagePictureBox.Height - 50 - limitY);

                            this.imageItemList.Add(this.imageItem);
                        }
                        catch(ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                }
            }

            if(this.shapeCheckBox.Checked)
            {
                if(this.shapeImageList.Count > 0)
                {
                    for(int i = 1; i <= this.shapeNumericUpDown.Value; i++)
                    {
                        try
                        {
                            this.imageItem = new ImageItem();

                            this.imageItem.LeftImage  = this.shapeImageList[this.random.Next(this.shapeImageList.Count)];
                            this.imageItem.RightImage = this.imageItem.LeftImage;
                            this.imageItem.Depth      = this.random.Next(1, this.shapeDepthTrackBar.Value / 2);
                            this.imageItem.Scale      = (float)(this.random.NextDouble() * .7 + .4);
                            this.imageItem.X          = (this.random.Next(this.imageItem.Depth, this.leftImagePictureBox.Width - this.imageItem.LeftImage.Width - this.imageItem.Depth) % 
                                                        this.leftImagePictureBox.Width) + this.imageItem.Depth;
                            this.imageItem.Y          = this.random.Next(this.leftImagePictureBox.Height - 100 - limitY);

                            this.imageItemList.Add(this.imageItem);
                        }
                        catch(ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                }
            }

            if(this.d3CheckBox.Checked)
            {
                if(this.d3LeftImageList.Count > 0)
                {
                    for(int i = 1; i <= this.d3NumericUpDown.Value; i++)
                    {
                        try
                        {
                            int imageIndex = this.random.Next(this.d3LeftImageList.Count);

                            this.imageItem = new ImageItem();

                            this.imageItem.LeftImage  = this.d3LeftImageList[imageIndex];
                            this.imageItem.RightImage = this.d3RightImageList[imageIndex];
                            this.imageItem.Depth      = this.random.Next(1, this.d3DepthTrackBar.Value / 2);
                            this.imageItem.Scale      = (float)(this.random.NextDouble() * .7 + .4);
                            this.imageItem.X          = (this.random.Next(this.imageItem.Depth, this.leftImagePictureBox.Width - this.imageItem.LeftImage.Width - this.imageItem.Depth) % 
                                                        this.leftImagePictureBox.Width) + this.imageItem.Depth;
                            this.imageItem.Y          = this.random.Next(this.leftImagePictureBox.Height - 100 - limitY);

                            this.imageItemList.Add(this.imageItem);
                        }
                        catch(ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                }
            }

            if(this.serialCheckBox.Checked)
            {
                if(this.shapeImageList.Count > 0)
                {
                    List<Image> imageList = new List<Image>();

                    int totalShapeCount = this.leftImagePictureBox.Width / 30;
                    
                    for(int k = 1; k <= this.serialNumericUpDown.Value; k++)
                    {
                        imageList.Add(this.shapeImageList[this.random.Next(this.shapeImageList.Count)]);
                    }

                    int x = 10 + this.serialDepthTrackBar.Value / 10;
                    int y;

                    for(int i = 1; i <= totalShapeCount ; i++)
                    {
                        x += (int)(i * this.leftImagePictureBox.Width / (10 * totalShapeCount));

                        y = this.leftImagePictureBox.Height - 30 - i * 12;

                        float scale = (float)(i + 1) / totalShapeCount;
                        int   depth = this.serialDepthTrackBar.Value / 20 * i;

                        for(int j = 1; j <= serialNumericUpDown.Value; j++)
                        {
                            try
                            {
                                this.imageItem = new ImageItem();

                                this.imageItem.LeftImage  = imageList[j - 1];
                                this.imageItem.RightImage = this.imageItem.LeftImage;
                                this.imageItem.X          = x;
                                this.imageItem.Y          = y - 60 * (j - 1);
                                this.imageItem.Depth      = depth + j;
                                this.imageItem.Scale      = scale * 80 / imageList[j - 1].Width;

                                this.imageItemList.Add(this.imageItem);
                            }
                            catch(ArgumentOutOfRangeException)
                            {
                                continue;
                            }
                        }
                    }
                }
            }

            for(int d = 0; d < 120; d++)
            {
                foreach(ImageItem imageItem in this.imageItemList)
                {
                    if(d == imageItem.Depth)
                    {
                        DrawPicture(leftBitmapGraphics, rightBitmapGraphics , imageItem);
                    }
                }

                if(this.showShadowCheckBox.Checked && this.showShadowCheckBox.Enabled && d == (int)(this.textDepthTrackBar.Value / 2 - 2))
                {
                    DrawText
                    (
                        this.textTextBox.Text,
                        leftBitmapGraphics,
                        rightBitmapGraphics,
                        10 + d,
                        20,
                        d,
                        new SolidBrush(this.shadowColorLabel.BackColor),
                        font,
                        4
                    );
                }

                if(this.showTextCheckBox.Checked && d == (int)(this.textDepthTrackBar.Value / 2))
                {
                    DrawText
                    (
                        this.textTextBox.Text,
                        leftBitmapGraphics,
                        rightBitmapGraphics,
                        10 + d,
                        20,
                        d,
                        new SolidBrush(this.textColorLabel.BackColor),
                        font,
                        0
                    );
                }
            }

            if(this.guideLineCheckBox.Checked)
            {
                for(int i = 0; i < 2; i++)
                {
                    leftBitmapGraphics.DrawLine
                    (
                        new Pen(this.guildeLineColorLabel.BackColor, 5),
                        i * this.leftImagePictureBox.Width - 1,
                        0,
                        i * (this.leftImagePictureBox.Width - 1),
                        this.leftImagePictureBox.Height
                    );

                    rightBitmapGraphics.DrawLine
                    (
                        new Pen(this.guildeLineColorLabel.BackColor, 5),
                        i * this.rightImagePictureBox.Width - 1,
                        0,
                        i * (this.rightImagePictureBox.Width - 1),
                        this.rightImagePictureBox.Height
                    );
                }
            }

            this.leftImagePictureBox.Image  = this.leftBitmap;
            this.rightImagePictureBox.Image = this.rightBitmap;

            if(this.autoSaveMenuItem.Checked)
            {
                SaveImage();
            }
        }

        #endregion
    }
}

 

▶ Program.cs

using System;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    static class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요