■ InkCanvas 클래스 : XAML 데이터 저장하기

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

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 fileStream = null;

 

    try

    {

        fileStream = 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, fileStream);

    }

    finally

    {

        if(fileStream != null)

        {

            fileStream.Close();

        }

    }

}

 

#endregion

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요