■ RenderTargetBitmap 클래스 : 객체 구하기

----------------------------------------------------------------------------------------------------

using System.Windows.Media;

using System.Windows.Media.Imaging;

 

#region RenderTargetBitmap 객체 구하기 - GetRenderTargetBitmap(pixelWidth, pixelHeight, dpiX, dpiY)

 

/// <summary>

/// RenderTargetBitmap 객체 구하기

/// </summary>

/// <param name="pixelWidth">픽셀 너비</param>

/// <param name="pixelHeight">픽셀 높이</param>

/// <param name="dpiX">DPI X</param>

/// <param name="dpiY">DPI Y</param>

/// <returns>RenderTargetBitmap 객체</returns>

public RenderTargetBitmap GetRenderTargetBitmap(int pixelWidth, int pixelHeight, double dpiX, double dpiY)

{

    RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap

    (

        pixelWidth,

        pixelHeight,

        dpiX,

        dpiY,

        PixelFormats.Pbgra32

    );

 

    DrawingVisual drawingVisual = new DrawingVisual();

 

    DrawingContext drawingContext = drawingVisual.RenderOpen();

 

    //////////////////////////////////////// 비트맵 그리기 시작

 

    double bitmapWidth  = GetDeviceIndependentUnitCount(pixelWidth , dpiX); // "장치 독립적 단위 수 구하기" 참조

    double bitmapHeight = GetDeviceIndependentUnitCount(pixelHeight, dpiY); // "장치 독립적 단위 수 구하기" 참조

 

    double penWidth = 10d;

 

    drawingContext.DrawRoundedRectangle

    (

        Brushes.Blue,

        new Pen(Brushes.Red, penWidth),

        new Rect(penWidth / 2d, penWidth / 2d, bitmapWidth - penWidth, bitmapHeight - penWidth),

        penWidth,

        penWidth

    );

 

    //////////////////////////////////////// 비트맵 그리기 종료

 

    drawingContext.Close();

 

    renderTargetBitmap.Render(drawingVisual);

 

    return renderTargetBitmap;

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요