728x90
반응형
728x170
using System.Drawing;
using System.Drawing.Imaging;
#region 회색조 비트맵 구하기 - GetGrayscaleBitmap(sourceBitmap)
/// <summary>
/// 회색조 비트맵 구하기
/// </summary>
/// <param name="sourceBitmap">소스 비트맵</param>
/// <returns>회색조 비트맵</returns>
public Bitmap GetGrayscaleBitmap(Bitmap sourceBitmap)
{
Bitmap targetBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height);
Graphics targetGraphics = Graphics.FromImage(targetBitmap);
ColorMatrix colorMatrix = new ColorMatrix
(
new float[][]
{
new float[] { .3f , .3f , .3f , 0, 0 },
new float[] { .59f, .59f, .59f, 0, 0 },
new float[] { .11f, .11f, .11f, 0, 0 },
new float[] { 0 , 0 , 0 , 1, 0 },
new float[] { 0 , 0 , 0 , 0, 1 }
}
);
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(colorMatrix);
targetGraphics.DrawImage
(
sourceBitmap,
new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height),
0,
0,
sourceBitmap.Width,
sourceBitmap.Height,
GraphicsUnit.Pixel,
imageAttributes
);
targetGraphics.Dispose();
return targetBitmap;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] PictureBox 클래스 : 사용자 선 그리기 (0) | 2020.07.05 |
---|---|
[C#/WINFORM] CommonOpenFileDialog 클래스 : 표준 윈도우즈 대화 상자를 사용해 폴더 선택하기 (0) | 2020.07.05 |
[C#/WINFORM] ListView 클래스 : 항목 인덱스 구하기 (0) | 2020.06.08 |
[C#/WINFORM] ListView 클래스 : 선택 항목 리스트 구하기 (0) | 2020.06.08 |
[C#/WINFORM] Control 클래스 : 컨트롤 비트맵 구하기 (0) | 2020.06.05 |
[C#/WINFORM/.NETCORE] WinForm .Net Core Class Library 사용하기 (0) | 2020.06.02 |
[C#/WINFORM] Label 클래스 : BackColor 속성을 사용해 투명 배경 설정하기 (0) | 2020.05.27 |
[C#/WINFORM] Cursor 클래스 : Position 정적 속성을 사용해 크레이지 커서 만들기 (0) | 2020.05.26 |
[C#/WINFORM] 윈도우 메시지(Window Message) 상수 (0) | 2020.05.22 |
[C#/WINFORM] Control 클래스 : ProcessCmdKey 메소드를 사용해 CTRL, SHIFT, ALT 조합 키 입력받기 (0) | 2020.05.22 |
댓글을 달아 주세요