첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요