1002版源代码http://vdisk.weibo.com/s/3PofL
一、概要设计
把程序分为3个主要模块,设计模块,拍照模块,拼接模块和一个额外的自动更新模块。
【设计模块】
主要的想法是把工具区的每个图形标上号,对应于显示在右边设计区的图形,姿势图片和覆盖在摄像头视频上的虚线框以及拍下的照片。
将设计区的图案按照标号转化为一个数组传到拍照模块。
【拍照模块】
接收到设计模块传来的设计数组,按照标号顺序进行检索,检索到存在该姿势,便进行拍照,把拍下的照片存在另一个数组中。
【拼接模块】
遍历设计模块的数组,更根据数组值去检索拍照模块拍出的照片。
额外的【自动更新模块】
在执行功能前打开自动更新程序,自动更新程序连接到服务器检查最新的版本,与客户端版本进行比较,如果客户端版本低于服务器上的版本,结束原有主程序,从服务器下载更新包(用自解压包装),下载完成后运行更新包,更新包自解压将原有老版本程序覆盖,更新完毕后会自动删除更新包自身。
二、详细设计
【设计模块】
设计模块主要用了GDI编程,利用各种GDI函数在PANEL控件上作画
private readonly int _iconNum = 17;
private readonly int _row = 9;
private readonly int _col = 2;
public int _imagerow = 5;
public int _imagecol = 6;
private readonly int _iconSize = 30;
private readonly int _imageSize = 50;
private PictureBox[,] _iconPictureBox;
private PictureBox[,] _imagePictureBox;
private int _pastX;
private int _pastY;
private int _selectedX = 0;
private int _selectedY = 0;
private int _selectedNum = 0;
static public int[] _imageList;
private StartFrom _startFrm;
private PrepareForm _prepareFrm;
System.Resources.ResourceManager _resources = new System.Resources.ResourceManager("主界面.Resource1",
Assembly.GetExecutingAssembly());
public DesignForm(StartFrom frm)
{
InitializeComponent();
_startFrm = frm;
this._iconPictureBox = new PictureBox[this._row, this._col];
}
重载了默认的构造函数,把开始界面的窗口作为参数传到设计窗口,避免了常用的新建窗口然后用hide和 show方法导致后台打开过多窗口。
public DesignForm(PrepareForm frm)
{
InitializeComponent();
_prepareFrm = frm;
this._iconPictureBox = new PictureBox[this._row, this._col];
}
private void design_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void IconPnl_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.WhiteSmoke, new Rectangle(0, 0, this.IconPnl.Width,
this.IconPnl.Height));
int index = 0;
for (int yPos = 0; yPos < this._row; yPos++)
{
for (int xPos = 0; xPos < this._col; xPos++)
{
if (index == this._iconNum)
break;
Image Image = (Image)this._resources.GetObject("_" + index);
this._iconPictureBox[yPos, xPos] = new PictureBox();
this._iconPictureBox[yPos, xPos].Image = Image;
g.DrawImage(Image, xPos * 31 + 1, yPos * 31 + 1, this._iconSize, this._iconSize);
// g.DrawRectangle(new Pen(Color.BlueViolet), new Rectangle(xPos*31, yPos*31, Image.Width+1, Image.Height+1));
drawFrame(g);
index++;
}
}
}
在工具区画出16中线条以及橡皮擦工具
private void drawFrame(Graphics g)//画框
{
for (int yPos = 0; yPos < this._row; yPos++)
{
for (int xPos = 0; xPos < this._col; xPos++)
{
if (this._iconPictureBox[yPos, xPos] != null)
g.DrawRectangle(new Pen(Color.BlueViolet), new Rectangle(xPos * 31, yPos * 31, 31, 31));
}
}
drawSelectedFrame(g);//画选择的框
}
private void drawSelectedFrame(Graphics g)//画出选择的红线
{
if (this._iconPictureBox[_selectedY, _selectedX] != null)
g.DrawRectangle(new Pen(Color.Red), new Rectangle(_selectedX * 31, _selectedY * 31, 30 + 1, 30 + 1));
}
private void IconPnl_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = IconPnl.CreateGraphics();
int xPos = e.X / 31;
int yPos = e.Y / 31;
if (_pastX == xPos && _pastY == yPos)
return;
// if (_selectedX == xPos && _selectedY == yPos)
// drawFrame(g);
_pastX = xPos;
_pastY = yPos;
if (yPos < this._row && xPos < this._col)
{
if (this._iconPictureBox[yPos, xPos] != null)
{
drawFrame(g);
if (_selectedX != xPos || _selectedY != yPos)//不是已经选择的才有黑框
g.DrawRectangle(new Pen(Color.Black), new Rectangle(xPos * 31, yPos * 31, 30 + 1, 30 + 1));
}
}
}
private void IconPnl_MouseLeave(object sender, EventArgs e)
{
Graphics g = IconPnl.CreateGraphics();//重新画框
drawFrame(g);
}
private void IconPnl_MouseDown(object sender, MouseEventArgs e)
{
Graphics g = IconPnl.CreateGraphics();
int xPos = e.X / 31;
int yPos = e.Y / 31;
_selectedX = xPos;
_selectedY = yPos;
if (yPos < this._row && xPos < this._col)
{
if (this._iconPictureBox[yPos, xPos] != null)
{
drawFrame(g);
_selectedNum = yPos * 2 + xPos;
//MessageBox.Show(_selectedNum.ToString());
// g.DrawRectangle(new Pen(Color.Red), new Rectangle(xPos * 31, yPos * 31, 30 + 1, 30 + 1));
}
}
}
private void DrawImagePanel(Graphics g)
{
//int index = 0;
g.FillRectangle(Brushes.WhiteSmoke, new Rectangle(0, 0, this.ImagePnl.Width,
this.ImagePnl.Height));
this._imagePictureBox = new PictureBox[this._imagerow, this._imagecol];
for (int yPos = 0; yPos < this._imagerow; yPos++)
{
for (int xPos = 0; xPos < this._imagecol; xPos++)
{
Image image = (Image)this._resources.GetObject("i" + _imageList[yPos * _imagecol + xPos]);
this._imagePictureBox[yPos, xPos] = new PictureBox();
this._imagePictureBox[yPos, xPos].Image = image;
g.DrawImage(image, xPos * 52 + 2, yPos * 52 + 2, this._imageSize, this._imageSize);
}
}
DrawImageFrame(g);
}
private void DrawImageFrame(Graphics g)
{
for (int yPos = 0; yPos < _imagerow; yPos++)
{
for (int xPos = 0; xPos < _imagecol; xPos++)
{
g.DrawRectangle(new Pen(Color.BlueViolet, 2), new Rectangle(xPos * 52 + 1, yPos * 52 + 1, 52, 52));
}
}
}
private void Design_HeartButton_Click(object sender, EventArgs e)
{
this._imagerow = 5;
this._imagecol = 6;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[] { 16,10,14,15, 8,16,
11,16,13,12,16, 7,
9,16,16,16,16, 5,
16, 2,16,16, 3,16,
16,16, 2, 3,16,16};
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void ImagePnl_MouseClick(object sender, MouseEventArgs e)
{
Graphics g = ImagePnl.CreateGraphics();
int xPos = e.X / 52;
int yPos = e.Y / 52;
if (yPos < this._imagerow && xPos < this._imagecol)
{
_imageList[yPos * this._imagecol + xPos] = _selectedNum;
//清空
Image image = (Image)this._resources.GetObject("i" + 16);
//this._imagePictureBox[yPos, xPos].Image = image;
g.DrawImage(image, xPos * 52 + 2, yPos * 52 + 2, this._imageSize, this._imageSize);
//绘图
Image image2 = (Image)this._resources.GetObject("i" + _imageList[yPos * _imagecol + xPos]);
this._imagePictureBox[yPos, xPos].Image = image;
g.DrawImage(image2, xPos * 52 + 2, yPos * 52 + 2, this._imageSize, this._imageSize);
}
}
private void Design_ILoveUButton_Click(object sender, EventArgs e)
{
this._imagerow = 6;
this._imagecol = 8;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[] { 16,16,16,16,16,16,16,16,
1,11, 2, 3, 7, 1,16, 1,
1, 5,16,16, 9, 1,16, 1,
1, 2,16,16, 3, 1,16, 1,
1,16, 2, 3,16,13, 0,12,
16,16,16,16,16,16,16,16};
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void Design_ChristsmasTreeButton_Click(object sender, EventArgs e)
{
this._imagerow = 6;
this._imagecol = 4;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[] { 16, 3, 2,16,
16, 5, 9,16,
11,16,16, 7,
3,16,16, 2,
16, 1, 1,16,
16, 1, 1,16};
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void Design_UmbrellaButton_Click(object sender, EventArgs e)
{
this._imagerow = 6;
this._imagecol = 5;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[] { 16,10, 0, 8,16,
3,16,16,16, 2,
0, 0, 0, 0, 0,
16,16, 1,16,16,
16,16, 1,16,16,
16,13,12,16,16};
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void Design_BigFaceButton_Click(object sender, EventArgs e)
{
this._imagerow = 5;
this._imagecol = 6;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[] { 15, 0, 0, 0, 0,14,
1,15,14,15,14, 1,
1,16,16,16,16, 1,
1,16,13,12,16, 1,
13, 0, 0, 0, 0,12};
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void Design_CustomButton_Click(object sender, EventArgs e)
{
this._imagerow = 5;
this._imagecol = 6;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[this._imagerow * this._imagecol];
for (int i = 0; i < this._imagerow * this._imagecol; i++)
_imageList[i] = 16;
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
// private void Design_CustomBigButton(object sender, EventArgs e)
// {
//
// }
private void ClearImageButton_Click(object sender, EventArgs e)
{
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[this._imagerow * this._imagecol];
for (int i = 0; i < this._imagerow * this._imagecol; i++)
_imageList[i] = 16;
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void DesignCustB_Click(object sender, EventArgs e)
{
this._imagerow = 6;
this._imagecol = 8;
ImagePnl.Size = new System.Drawing.Size(52 * this._imagecol + 2, 52 * this._imagerow + 2);
_imageList = new int[this._imagerow * this._imagecol];
for (int i = 0; i < this._imagerow * this._imagecol; i++)
_imageList[i] = 16;
Graphics g = ImagePnl.CreateGraphics();
DrawImagePanel(g);
}
private void BackToStartPnl_MouseEnter(object sender, EventArgs e)
{
BackToStartPnl.BackgroundImage = 主界面.Resource1.canvas_b_on;
}
private void BackToStartPnl_MouseLeave(object sender, EventArgs e)
{
BackToStartPnl.BackgroundImage = 主界面.Resource1.canvas_b;
}
private void ContinuePnl_MouseEnter(object sender, EventArgs e)
{
ContinuePnl.BackgroundImage = 主界面.Resource1.canvas_f_on;
}
private void ContinuePnl_MouseLeave(object sender, EventArgs e)
{
ContinuePnl.BackgroundImage = 主界面.Resource1.canvas_f;
}
private void BackToStartPnl_MouseClick(object sender, MouseEventArgs e)
{
if (_startFrm == null)
{
_startFrm = new StartFrom(this);
_startFrm.Location = this.Location;
this.Opacity = 0;
_startFrm.Show();
// this.ShowInTaskbar = false;
}
else
{
_startFrm.Location = this.Location;
this.Opacity = 0;
_startFrm.Opacity = 100;
// _startFrm.ShowInTaskbar = true;
// this.ShowInTaskbar = false;
}
}
private void ContinuePnl_MouseClick(object sender, MouseEventArgs e)
{
if (_imageList != null)
{
// if (_prepareFrm == null)
// {
_prepareFrm = new PrepareForm(this,_imagerow,_imagecol);
_prepareFrm.Location = this.Location;
this.Opacity=0;
_prepareFrm.Show();
// }
// else
// {
// _prepareFrm.Location = this.Location;
// this.Opacity = 0;
// _prepareFrm.Opacity = 100;
// }
}
else
{
MessageBox.Show("亲,你好像还没有设计图像哦", "啊哦,发生了一个小错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void DesignForm_Shown(object sender, EventArgs e)
{
Design_HeartButton_Click(Design_HeartButton, null);
}
// private void DesignForm_Activated(object sender, EventArgs e)
// {
// Design_HeartButton_Click(Design_HeartButton, null);
// }
先写到这里。。。。稍后更新