■ 컨트롤 이미지 저장하기

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

using System.IO;

using System.Windows;

using System.Windows.Media;

using System.Windows.Media.Imaging;

 

#region 이미지 저장하기 - SaveImage(frameworkElement, filePath)

 

/// <summary>

/// 이미지 저장하기

/// </summary>

/// <param name="frameworkElement">프레임워크 엘리먼트</param>

/// <param name="filePath">파일 경로</param>

public void SaveImage(FrameworkElement frameworkElement, string filePath)

{

    RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap

    (

        (int)frameworkElement.ActualWidth,

        (int)frameworkElement.ActualHeight,

        96d,

        96d,

        PixelFormats.Default

    );

 

    renderTargetBitmap.Render(frameworkElement);

 

    using(Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))

    {

        JpegBitmapEncoder encoder = new JpegBitmapEncoder();

 

        encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));

 

        encoder.Save(stream);

    }

}

 

#endregion

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

Posted by 사용자 icodebroker

댓글을 달아 주세요