첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System.IO;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Markup;
using System.Windows.Media;

#region XAML 데이터 저장하기 - SaveXAMLData(inkCanvas, filePath)

/// <summary>
/// XAML 데이터 저장하기
/// </summary>
/// <param name="inkCanvas">InkCanvas 객체</param>
/// <param name="filePath">파일 경로</param>
public void SaveXAMLData(InkCanvas inkCanvas, string filePath)
{
    FileStream stream = null;

    try
    {
        stream = new FileStream(filePath, FileMode.Create, FileAccess.Write);

        DrawingGroup drawingGroup = new DrawingGroup();

        foreach(Stroke stroke in inkCanvas.Strokes)
        {
            Color color = stroke.DrawingAttributes.Color;

            if(stroke.DrawingAttributes.IsHighlighter)
            {
                color = Color.FromArgb(128, color.R, color.G, color.B);
            }

            drawingGroup.Children.Add
            (
                new GeometryDrawing
                (
                    new SolidColorBrush(color),
                    null,
                    stroke.GetGeometry()
                )
            );
        }

        XamlWriter.Save(drawingGroup, stream);
    }
    finally
    {
        if(stream != null)
        {
            stream.Close();
        }
    }
}

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

댓글을 달아 주세요