Windows Phone简易绘画板

启动画面:

 


 


主画面:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
//
using System.Windows.Ink;

namespace Painter
{
    public partial class MainPage : PhoneApplicationPage
    {
        public Point pre;
        static readonly string[ ] strColors = { "Black", "Blue", "Brown", "Cyan", "Green", "Orange", "Purple", "Red" };
        int strokeSize;
        Color strokeColor;
        //double strokeOpacity;
        // 构造函数  
        public MainPage()
        {
            InitializeComponent();
            InitItemPicker(); //控件初始化
        }
        
        private void MyPresenter_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            StylusPoint sp_start = new StylusPoint(pre.X,pre.Y);//起点为上一次的终点
            StylusPoint sp_end = new StylusPoint(e.ManipulationOrigin.X, e.ManipulationOrigin.Y);//终点为本次触点
            StylusPointCollection strokePoints = new StylusPointCollection();
            
            strokePoints.Add(sp_start);
            strokePoints.Add(sp_end);

            Stroke newStroke = new Stroke(strokePoints);
            
            //设置笔触的粗细
            newStroke.DrawingAttributes.Width = strokeSize;
            newStroke.DrawingAttributes.Height=strokeSize;
            //笔触的颜色
            newStroke.DrawingAttributes.Color = strokeColor;
            
            MyPresenter.Strokes.Add(newStroke);
            pre.X = e.ManipulationOrigin.X;
            pre.Y = e.ManipulationOrigin.Y;
        }

        private void MyPresenter_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            pre = new Point(e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
        }

        private void InitItemPicker()
        {
            listPicker1.Header = "画笔粗细";
            for (int i = 1; i <= 31; i+=2)
                listPicker1.Items.Add(i);
            listPicker2.Header = "画笔颜色";
            listPicker2.DataContext = strColors;
        }

        private void listPicker2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch( listPicker2.SelectedItem.ToString() )//好笨的办法
            {
                case "Black":
                    strokeColor=Colors.Black;
                    break;
                case "Blue":
                    strokeColor = Colors.Blue;
                    break;
                case "Brown":
                    strokeColor = Colors.Brown;
                    break;
                case "Cyan":
                    strokeColor = Colors.Cyan;
                    break;
                case "Green":
                    strokeColor = Colors.Green;
                    break;
                case "Orange":
                    strokeColor = Colors.Orange;
                    break;
                case "Purple":
                    strokeColor = Colors.Purple;
                    break;
                case "Red":
                    strokeColor = Colors.Red;
                    break;
            }
        }

        private void listPicker1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            strokeSize = int.Parse(listPicker1.SelectedItem.ToString());
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            //MessageBox.Show( e.NewValue.ToString() );
            strokeColor.A = (byte)(e.NewValue * 25.5);   //0~1 转换为 0~255  蛋疼的单位不一致
        }
    }
}


 
接下来,只要再加上“保存图片”和“重置画布”就基本完工了~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值