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

■ BitmapSource 클래스를 사용해 픽셀 바이트 배열을 구하는 방법을 보여준다.

 

▶ 예제 코드 (C#)

using System.Windows.Media.Imaging;

#region 픽셀 바이트 배열 구하기 - GetPixelByteArray(bitmapSource)

/// <summary>
/// 픽셀 바이트 배열 구하기
/// </summary>
/// <param name="bitmapSource">비트맵 소스</param>
/// <returns>픽셀 바이트 배열</returns>
public byte[] GetPixelByteArray(BitmapSource bitmapSource)
{
    int bitCountPerPixel = bitmapSource.Format.BitsPerPixel;
    int pixelWidth       = bitmapSource.PixelWidth;
    int pixelHeight      = bitmapSource.PixelHeight;
    int stride           = (pixelWidth * bitCountPerPixel + 7) / 8;

    byte[] byteArray = new byte[stride * bitmapSource.PixelHeight];

    bitmapSource.CopyPixels(byteArray, stride, 0);

    return byteArray;
}

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

댓글을 달아 주세요