Windows Moblie 笔迹图板开发

这是应一个网友的问题而做的一个小程序,可以保存为位图,我觉得还是有一定的参考价值的,所以就把相关代码贴了出来。

Windows Moblie 笔迹图板开发

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HandImage
{
public partial class frmTest:Form
{
List
< Points > HandTrack = new List < Points > ();
public Graphicspb_Graphics;
Bitmappb_BMP
= new Bitmap( 239 , 235 );

int index = 0 ; // 第几笔
public frmTest()
{
InitializeComponent();
}

private void pnlBar_MouseMove( object sender,MouseEventArgse)
{
HandTrack[index].PT.Add(
new Point(e.X,e.Y));
pnlBar.Refresh();
}

private void pnlBar_Paint( object sender,PaintEventArgse)
{
pb_Graphics
= Graphics.FromImage((System.Drawing.Image)pb_BMP);
pb_Graphics.Clear(pnlBar.BackColor);
foreach (Pointsitem in HandTrack)
{
pb_Graphics.DrawLines(
new Pen(Color.Black),item.PT.ToArray());
}
e.Graphics.DrawImage(pb_BMP,
0 , 0 );
pb_Graphics.Dispose();
}

class Points
{
public List < Point > PT = new List < Point > ();
}

private void btnClear_Click( object sender,EventArgse)
{
index
= 0 ;
HandTrack
= new List < Points > ();
pnlBar.Refresh();
}

private void pnlBar_MouseUp( object sender,MouseEventArgse)
{
index
++ ;
}

private void pnlBar_MouseDown( object sender,MouseEventArgse)
{
HandTrack.Add(
new Points());
HandTrack[index].PT.Add(
new Point(e.X,e.Y));
pnlBar.Refresh();
}

private void btnSave_Click( object sender,EventArgse)
{
dlgSaveFile.Filter
= " 位图(*.bmp)|*.bmp " ;
if (dlgSaveFile.ShowDialog() == DialogResult.OK)
{
string strFile = dlgSaveFile.FileName;
pb_BMP.Save(strFile,System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
}

你可能感兴趣的:(windows)