启动画面:
主画面:

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 蛋疼的单位不一致
}
}
}
接下来,只要再加上“保存图片”和“重置画布”就基本完工了~