728x90
반응형
728x170
▶ 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.sourcePictureBox.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)
{
this.redPictureBox.Image = GetChannelImage(this.sourcePictureBox.Image, 1, 0, 0, 1);
this.greenPictureBox.Image = GetChannelImage(this.sourcePictureBox.Image, 0, 1, 0, 1);
this.bluePictureBox.Image = GetChannelImage(this.sourcePictureBox.Image, 0, 0, 1, 1);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 채널 이미지 구하기 - GetChannelImage(sourceImage, red, green, blue, alpha)
/// <summary>
/// 채널 이미지 구하기
/// </summary>
/// <param name="sourceImage">소스 이미지</param>
/// <param name="red">빨강색 채널</param>
/// <param name="green">녹색 채널</param>
/// <param name="blue">파랑색 채널</param>
/// <param name="alpha">투명도 채널</param>
/// <returns>비트맵</returns>
private Bitmap GetChannelImage(Image sourceImage, float red, float green, float blue, float alpha)
{
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 , alpha, 0 },
new float[] {0 , 0 , 0 , 0 , 1 },
}
);
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(colorMatrix);
Point[] pointArray =
{
new Point(0, 0),
new Point(sourceImage.Width - 1, 0),
new Point(0, sourceImage.Height - 1),
};
Rectangle rectangle = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
Bitmap bitmap = new Bitmap(sourceImage.Width, sourceImage.Height);
using(Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.DrawImage(sourceImage, pointArray, rectangle, GraphicsUnit.Pixel, imageAttributes);
}
return bitmap;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 다항식 최소 제곱법(Polynomial Least Squares Method) 사용하기 (0) | 2018.12.19 |
---|---|
[C#/WINFORM] 선형 최소 제곱법(Linear Least Squares Method) 사용하기 (0) | 2018.12.19 |
[C#/WINFORM] ColorDialog 클래스 : 커스텀 색상 사용하기 (0) | 2018.12.19 |
[C#/WINFORM] ImageAttributes 클래스 : 무지개 색상 이미지 구하기 (0) | 2018.12.19 |
[C#/WINFORM] ImageAttributes 클래스 : 색상 이미지 구하기 (0) | 2018.12.19 |
[C#/WINFORM] ImageAttributes 클래스 : 세피아 이미지 구하기 (0) | 2018.12.18 |
[C#/WINFORM] ImageAttributes 클래스 : 모노크롬 이미지 구하기 (0) | 2018.12.18 |
[C#/WINFORM] ImageAttributes 클래스 : 이미지 명도 조정하기 (0) | 2018.12.18 |
[C#/WINFORM] Bitmap 클래스 : 회색조 비트맵 구하기 (0) | 2018.12.18 |
[C#/WINFORM] 문단 JUSTIFY 정렬하기 (0) | 2018.12.16 |
댓글을 달아 주세요