728x90
728x170
■ InkCanvas 클래스에서 ISF(Ink Serialized Format) 파일을 로드하고 저장하는 방법을 보여준다.
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="TestProject"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0"
BorderThickness="2"
BorderBrush="Black">
<InkCanvas Name="inkCanvas" />
</Border>
<StackPanel Grid.Row="1"
HorizontalAlignment="Center"
Margin="10"
Orientation="Horizontal">
<Button Name="loadButton"
Width="100"
Height="30"
Content="로드하기" />
<Button Name="saveButton"
Margin="10 0 0 0"
Width="100"
Height="30"
Content="저장하기" />
<Button Name="clearButton"
Margin="10 0 0 0"
Width="100"
Height="30"
Content="지우기" />
</StackPanel>
</Grid>
</Window>
▶ MainWindow.xaml.cs
using System.IO;
using System.Windows;
using System.Windows.Ink;
using Microsoft.Win32;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 파일 열기 대화 상자
/// </summary>
private OpenFileDialog openFileDialog;
/// <summary>
/// 파일 저장하기 대화 상자
/// </summary>
private SaveFileDialog saveFileDialog;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.openFileDialog = new OpenFileDialog();
this.openFileDialog.Filter = "isf 파일 (*.isf)|*.isf";
this.saveFileDialog = new SaveFileDialog();
this.saveFileDialog.Filter = "isf 파일 (*.isf)|*.isf";
this.loadButton.Click += loadButton_Click;
this.saveButton.Click += saveButton_Click;
this.clearButton.Click += clearButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 로드하기 버튼 클릭시 처리하기 - loadButton_Click(sender, e)
/// <summary>
/// 로드하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void loadButton_Click(object sender, RoutedEventArgs e)
{
if(this.openFileDialog.ShowDialog() == true)
{
using(FileStream fileStream = new FileStream(this.openFileDialog.FileName, FileMode.Open))
{
this.inkCanvas.Strokes = new StrokeCollection(fileStream);
}
}
}
#endregion
#region 저장하기 버튼 클릭시 처리하기 - saveButton_Click(sender, e)
/// <summary>
/// 저장하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void saveButton_Click(object sender, RoutedEventArgs e)
{
if(this.saveFileDialog.ShowDialog() == true)
{
using(FileStream fileStream = new FileStream(this.saveFileDialog.FileName, FileMode.Create))
{
this.inkCanvas.Strokes.Save(fileStream);
}
}
}
#endregion
#region 지우기 버튼 클릭시 처리하기 - clearButton_Click(sender, e)
/// <summary>
/// 지우기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void clearButton_Click(object sender, RoutedEventArgs e)
{
this.inkCanvas.Strokes.Clear();
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] InkCanvas 클래스 : 잉크 데이터에 커스텀 데이터 추가하기 (0) | 2022.11.27 |
---|---|
[C#/WPF] UIElement 클래스 : 잉크 입력 컨트롤에서 잉크 선택하기 (0) | 2022.11.26 |
[C#/WPF] UIElement 클래스 : 잉크 입력 컨트롤 만들기 (0) | 2022.11.26 |
[C#/WPF] InkCanvas 클래스 : StylusPlugIns 속성을 사용해 커스텀 스타일러스 플러그인 설정하기 (0) | 2022.11.26 |
[C#/WPF] InkCanvas 클래스 : 커스텀 렌더링 잉크 사용하기 (0) | 2022.11.26 |
[C#/WPF] InkCanvas 클래스 : 필기 인식하기 (0) | 2022.11.24 |
[C#/WPF] InkCanvas 클래스 : GetSelectedStrokes 메소드를 사용해 선택 스트로크 색상 변경하기 (0) | 2022.11.22 |
[C#/WPF] InkCanvas 클래스 : DefaultDrawingAttributes 속성을 사용해 스트로크 모양 설정하기 (0) | 2022.11.22 |
[C#/WPF] InkCanvas 클래스 : MouseRightButtonUp 이벤트를 사용해 스트로크 크기 확대하기 (0) | 2022.11.22 |
[C#/WPF] Matrix 구조체 : Scale 메소드를 사용해 크기 확대하기 (0) | 2022.11.22 |