A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 吴冕 中级黑马   /  2013-4-23 20:53  /  1545 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

用WPF实现数字墨水手绘涂鸦
要支持中文,求思路

1 个回复

倒序浏览
<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();

        }

    }

}

希望对你有用!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马