黑马程序员技术交流社区

标题: wpf实现数字涂鸦? [打印本页]

作者: 吴冕    时间: 2013-4-23 20:53
标题: wpf实现数字涂鸦?
用WPF实现数字墨水手绘涂鸦
要支持中文,求思路

作者: 极限冰风    时间: 2013-4-23 21:31
<Window x:Class="数字墨迹.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="www.cnblogs.com" Closing="Window_Closing" Initialized="Window_Initialized" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">

    <Grid>

        <InkCanvas Background="{StaticResource back}" Width="435" Height="300" Name="ink">

            <InkCanvas.DefaultDrawingAttributes>

                <DrawingAttributes Color="#882F515B" IsHighlighter="True" StylusTip="Rectangle" Height="4" Width="2" IgnorePressure="True" FitToCurve="True">

                    <DrawingAttributes.StylusTipTransform>

                        <Matrix M11="1" M12="1.5" M21="2.2" M22="1"/>

                    </DrawingAttributes.StylusTipTransform>

                </DrawingAttributes>

            </InkCanvas.DefaultDrawingAttributes>

        </InkCanvas>

    </Grid>

</Window>

后台代码!


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;



namespace 数字墨迹

{

    /**//// <summary>

    /// Window1.xaml 的交互逻辑

    /// </summary>

    public partial class Window1 : Window

    {

        public Window1()

        {

            InitializeComponent();

        }



        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)

        {

            var f = new System.IO.FileStream("pic.ink", System.IO.FileMode.OpenOrCreate);

            ink.Strokes.Save(f);

            f.Close();

        }



        private void Window_Initialized(object sender, EventArgs e)

        {

            var f = new System.IO.FileStream("pic.ink", System.IO.FileMode.Open);

            if (System.IO.File.Exists("pic.ink")) ink.Strokes = new System.Windows.Ink.StrokeCollection(f);

            f.Close();

        }

    }

}

希望对你有用!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2