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

■ RenderTargetBitmap 클래스를 사용해 Image 객체에서 비트맵을 구하는 방법을 보여준다.

 

▶ 예제 코드 (C#)

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

#region 비트맵 구하기 - GetBitmap(image)

/// <summary>
/// 비트맵 구하기
/// </summary>
/// <param name="image">이미지</param>
/// <returns>렌더 타겟 비트맵</returns>
public RenderTargetBitmap GetBitmap(Image image)
{
    RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap
    (
        (int)image.ActualWidth,
        (int)image.ActualHeight,
        96.0,
        96.0,
        PixelFormats.Pbgra32
    );

    image.Measure(new Size((int)image.ActualWidth, (int)image.ActualHeight));

    image.Arrange(new Rect(new Size((int)image.ActualWidth, (int)image.ActualHeight)));

    renderTargetBitmap.Render(image);

    return renderTargetBitmap;
}

#endregion

※ Image 객체가 메모리에 로드된 다음 상기 함수를 사용해야 한다.

728x90
그리드형(광고전용)
Posted by icodebroker
,