C#课程设计报告.docx
- 文档编号:5403707
- 上传时间:2022-12-16
- 格式:DOCX
- 页数:21
- 大小:250.43KB
C#课程设计报告.docx
《C#课程设计报告.docx》由会员分享,可在线阅读,更多相关《C#课程设计报告.docx(21页珍藏版)》请在冰豆网上搜索。
C#课程设计报告
河北工程大学
科信学院
课程设计说明书
(2010/2011学年第二学期)
课程名称:
C#课程设计
题目:
缩略图生成器
专业班级:
通信工程08-02
学生姓名:
学号:
指导教师:
设计周数:
2周
设计成绩:
2011年7月9日
目录
1、课程设计目的1
2、软件的分析与设计1
2.1软件分析1
2.1.1课程设计的任务1
2.1.2课程设计的要求1
2.2软件设计2
2.2.1数据库的分析与设计2
2.2.2逻辑层次的设计2
2.2.3主界面的设计3
2.3程序设计3
2.3.1程序流程图3
2.3.2软件运行过程4
2.3.3实现结果14
3、课程设计总结15
4、参考文献15
1、课程设计目的
(1)通过本次设计掌握VisualStudio中Windows窗体的建立及窗体中各个控件的使用,以及界面的设计
(2)进一步熟悉了所学的C#语言的编程,对编程有了进一步巩固,并提高分析和解决实际问题的能力
(3)初步掌握使用VisualStudio建立软件的这一功能。
熟悉了软件的设计,调试的全过程
2、系统分析与设计
缩略图生成器是一款可以对图像进行处理的软件,用户可以根据自己的需求使用该软件对图像进行处理,比如由于图片过大而无法上传,或者是需要实现批量缩放等,实现这些功能,在一定程度上给需求者带来了极大的方便。
本课程设计实现了一个具有这些功能的缩略图生成器,用户可以使用该软件实习自己所需的一些功能。
但本软件也有一些不足之处,就是没有实现等比例不失真生成缩略图。
2.1系统分析
2.1.1课程设计的任务
(1)根据技术要求和现有开发环境,分析题目
(2)软件设计方案。
包括:
软件功能结构、各功能模块的详细描述、关键程序流程图等。
(3)使用C#语言,实现软件;
(4)调试、修改并完善程序;
(5)生成安装程序,编写软件使用说明书(图文结合进行描述);
(6)撰写课程设计报告。
2.1.2课程设计的要求
(1)单张图片生成缩略图和批量图片生成缩略图;
(2)自定义缩略图的宽和高,等比例不失真的生成缩略图;
(3)生成缩略图文件命名规则定制;
(4)生成文件存放路径的自定义。
2.2系统的设计
本软件是一款基于VisualStudio系统的软件,简单易操作。
只有VisualStudio2005及更高的版本下才能使用,本软件实现了以下功能:
(1)单张图片生成缩略图和批量图片生成缩略图;
(2)自定义图片的高和宽;
(3)生成缩略图文件命名规则的定制;
(4)生成文件存放路径的自定义。
2.2.1逻辑层次的设计
本次设计的软件可以实现单张和多张图片的缩略,自定义图片的高和宽,自定义保存路径和自定义图片命名规则。
缩略图生成器的基本结构框图如图1所示
图1缩略图生成器基本结果框架
2.2.3主界面的设计
本软件界面简单明了,很方便用户的使用和操作。
在主界面上设有图片预览、设置、说明和退出按钮。
用户可以根据自已的需要,对该软件进行操作。
缩略图生成器界面设计如图2所示:
图2缩略图生成器的界面设计
2.3程序设计
用户打开该软件进入到该软件的界面后,点击菜单栏上文件、设置、说明和退出等按钮,就可以根据自己的需要,对图片进行相关的设定,达到自己所需的效果。
2.3.1程序流程图
单张生成缩略图程序流程图如图4所示:
图4
多张生成缩略图程序流程图如图5所示:
图5
2.3.2软件运行过程
本软件主要通过运用C#的Windows窗体的设计进行开发和实施,在VisualStudio2005及更高的版本下才能运行。
主要通过如下几个功能模块来完成软件的具体的运行过程:
(1)主界面窗体:
主界面如图6所示:
图6
具体实现的代码如下:
publicpartialclassForm1:
Form
{
BitmapMyBitmap;
publicForm1()
{
InitializeComponent();
}
privatevoid退出CToolStripMenuItem_Click(objectsender,EventArgse)
{
if(MessageBox.Show("退出系统?
","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK)
{
Application.Exit();
}
}
privatevoid打开ToolStripMenuItem_Click(objectsender,EventArgse)
{
openFileDialog1.Filter="*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";//设置打开图像的类型
this.openFileDialog1.ShowDialog();//打开对话框
if(this.openFileDialog1.FileName.Trim()=="")
return;
try
{
//把打开的图像赋给Bitmap变量
BitmapSrcBitmap=newBitmap(this.openFileDialog1.FileName);
MyBitmap=newBitmap(SrcBitmap,this.pictureBox1.Width,this.pictureBox1.Height);
this.pictureBox1.Image=MyBitmap;//在控件上显示图像
}
catch(ExceptionErr)
{
//提示对话框
MessageBox.Show(this,"打开图像文件错误!
","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
privatevoid另存为ToolStripMenuItem_Click(objectsender,EventArgse)
{
if(this.openFileDialog1.FileName.Trim()=="")
return;
try
{
saveFileDialog1.Filter="BMP|*.bmp|JPEG|*.jpeg|GIF|*.gif|PNG|*.png";
if(saveFileDialog1.ShowDialog()==DialogResult.OK)
{
stringpicPath=saveFileDialog1.FileName;
stringpicType=picPath.Substring(picPath.LastIndexOf(".")+1,(picPath.Length-picPath.LastIndexOf(".")-1));
switch(picType)
{
case"bmp":
Bitmapbt=newBitmap(pictureBox1.Width,pictureBox1.Height);
pictureBox1.DrawToBitmap(bt,pictureBox1.ClientRectangle);
bt.Save(picPath,ImageFormat.Bmp);
bt.Dispose();
break;
case"jpeg":
Bitmapbt1=newBitmap(pictureBox1.Width,pictureBox1.Height);
pictureBox1.DrawToBitmap(bt1,pictureBox1.ClientRectangle);
bt1.Save(picPath,ImageFormat.Jpeg);
bt1.Dispose();
break;
case"gif":
Bitmapbt2=newBitmap(pictureBox1.Width,pictureBox1.Height);
pictureBox1.DrawToBitmap(bt2,pictureBox1.ClientRectangle);
bt2.Save(picPath,ImageFormat.Gif);
bt2.Dispose();
break;
case"png":
Bitmapbt3=newBitmap(pictureBox1.Width,pictureBox1.Height);
pictureBox1.DrawToBitmap(bt3,pictureBox1.ClientRectangle);
bt3.Save(picPath,ImageFormat.Png);
bt3.Dispose();
break;
}
}
}
catch(Exceptionerr)
{
MessageBox.Show(err.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
privatevoid单张生成缩略图ToolStripMenuItem_Click(objectsender,EventArgse)
{
Form2ys=newForm2();
//ys.MdiParent=this;
ys.Show();
}
privatevoid多张生成缩略图ToolStripMenuItem_Click(objectsender,EventArgse)
{
Form2ys=newForm2();
ys.Show();
}
privatevoid关于本软件ToolStripMenuItem_Click(objectsender,EventArgse)
{
frmAboutfrm=newfrmAbout();
DialogResultrst=frm.ShowDialog();
}
privatevoid访问作者空间ToolStripMenuItem_Click(objectsender,EventArgse)
{
System.Diagnostics.Process.Start("Http:
//1010085285QQ.com");
}
privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)
{
if(MessageBox.Show("退出系统?
","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK)
{
Application.Exit();
}
}
privatevoid文件ToolStripMenuItem_Click(objectsender,EventArgse)
{
}
}
(2)单张生成缩略图窗体:
界面如图7所示:
图7
具体实现的代码如下:
privatevoidgo()
{
try
{
//判断文件是否存在
if(this.openFileDialog1.FileName.Trim().Length<=0)
{
MessageBox.Show("请先选择一个文件");
return;
}
if(!
setConfig()||!
setSave())
{
return;
}
stringoriPath=this.openFileDialog1.FileName;
this.openFileDialog1.Dispose();//该行可以不注释,为避免发生资源占用不能替换源文件所以还是注释。
this.pictureBox1.Image.Dispose();//在处理之前必须断开pic对image的引用否则无法替换源文件
this.pictureBox1.Image=null;//断开引用后需要赋值为null,否则形同虚设。
if(this.checkBox1.Checked)
{
c.Make_Thumbnail2(oriPath,filename,width,height,"HW");
}
if(this.checkBox2.Checked)
{
c.Make_Thumbnail2(oriPath,filename,width,height,"scale");
}
if(this.checkBox3.Checked)
{
c.Make_Thumbnail2(oriPath,filename,width,height,"hscale");
}
if(this.checkBox4.Checked)
{
c.Make_Thumbnail2(oriPath,filename,width,height,"wscale");
}
this.pictureBox1.Image=Image.FromFile(oriPath);
MessageBox.Show("执行成功!
请检查相应的文件");
}
catch(Exceptiones)
{
MessageBox.Show("有异常!
"+es.Message);
}
}
(3)多张生成缩略图窗体:
界面如图8所示:
具体实现的代码如下:
privatevoidall(stringfile_path,stringresult_path)
{
try
{
if(!
setConfig())
{
return;
}
stringtemp_path="";
stringtype="HW";
string[]filenames=Directory.GetFiles(file_path,"*.jpg",SearchOption.AllDirectories);
if(this.checkBox1.Checked)
{
type="HW";
}
if(this.checkBox2.Checked)
{
type="scale";
}
if(this.checkBox3.Checked)
{
type="hscale";
}
if(this.checkBox4.Checked)
{
type="wscale";
}
System.Diagnostics.Process.Start("explorer.exe",file_path);
HashtablefileExtensions=newHashtable(10);
fileExtensions.Add(".jpg",null);
fileExtensions.Add(".bmp",null);
fileExtensions.Add(".gif",null);
fileExtensions.Add(".png",null);
stringfindPath=file_path;
DirectoryInfodi=newDirectoryInfo(findPath);
FileInfo[]fiels=di.GetFiles("*.*",SearchOption.AllDirectories);
foreach(FileInfofiinfiels)
{
if(fileExtensions.Contains(fi.Extension.ToLower()))
{
//this.label7.Text=label7.Text+","+fi.Name;//测试打印文件名
temp_path=file_path+fi.Name;
c.Make_Thumbnail2(temp_path,result_path+fi.Name,width,height,type);
}
}
MessageBox.Show("执行成功!
");
}
catch(Exceptiones)
{
MessageBox.Show("批量执行有异常!
"+es.Message);
}
}
(4)缩略图缩放规则窗体:
界面设置如图9所示:
图9
具体实现代码:
privateintwidth;
privateintheight;
privateboolsetConfig()
{
if(this.checkBox1.Checked)
{
if(this.textBox3.Text.Trim().Length>0)
{
this.width=Convert.ToInt32(this.textBox3.Text.Trim());
}
else
{
MessageBox.Show("请填写高度!
");
this.textBox3.Focus();
returnfalse;
}
if(this.textBox4.Text.Trim().Length>0)
{
this.height=Convert.ToInt32(this.textBox4.Text.Trim());
}
else
{
MessageBox.Show("请填写宽度!
");
this.textBox4.Focus();
returnfalse;
}
}
elseif(this.checkBox2.Checked)
{
if(this.textBox5.Text.Trim().Length>0)
{
this.width=Convert.ToInt32(this.textBox5.Text.Trim());
this.height=width;
}
else
{
MessageBox.Show("请填写缩放比例!
");
this.textBox5.Focus();
returnfalse;
}
}
elseif(this.checkBox3.Checked)
{
if(this.textBox6.Text.Trim().Length>0)
{
this.height=Convert.ToInt32(this.textBox6.Text.Trim());
this.width=0;
}
else
{
MessageBox.Show("请填写高度度缩放比例!
");
this.textBox6.Focus();
returnfalse;
}
}
elseif(this.checkBox4.Checked)
{
if(this.textBox7.Text.Trim().Length>0)
{
this.width=Convert.ToInt32(this.textBox7.Text.Trim());
this.height=0;
}
else
{
MessageBox.Show("请填写宽度缩放比例!
");
this.textBox7.Focus();
returnfalse;
}
}
returntrue;
}
(4)缩略图命名规则窗体:
界面设计如图10所示:
图10
具体实现代码:
tringfilename=string.Empty;
privateboolsetSave()
{
if(this.checkBox5.Checked)
{
this.filename=this.openFileDialog1.FileName;
}
elseif(this.checkBox6.Checked)
{
if(this.textBox8.Text.Trim().Length>0)
{
stringtemp=this.openFileDialog1.FileName;
stringext_temp=System.IO.Path.GetExtension(temp).ToLower();
intindexof=temp.LastIndexOf('\\')+1;
this.filename=temp.Substring(0,indexof);
this.filename=filename+this.textBox8.Text.Trim()+ext_temp;
}
else
{
MessageBox.Show("请填写文件名!
");
this.textBox8.Focus();
returnfalse;
}
}
elseif(this.checkBox7.Checked)
{
if(this.textBox9.Text.Trim().Length>0)
{
this.filename=this.textBox9.Text.Trim();
}
else
{
MessageBox.Show("请填写完整路径和文件名!
");
this.textBox9.Focus();
returnfalse;
}
}
returntrue;
}
2.3.3实现结果
处理前:
处理后:
3、课程设计总结
两周时间的课程设计结束了。
两周以来,通过我们组所有成员的努力,和老师细心指导,我们完成了这次的课程设计—--缩略图生成器的设计。
面对从未接触过的事情,开始的我们不知道从何下手,在一步步的实践中,我们慢慢摸索出一点头绪,通过网络、书籍和老师的指导,我们终于找到了方法,最终将设计做好了。
两周的时间说长是因为天天面对那些框啊代码啊,感觉很枯燥乏味,说时间短是因为我们真的从中找到了乐趣,学到了知识学,懂得如何与团队合作,深切体会到了应该怎么样去面对困难。
在这短短两周的时间里,自己学到了很多东西,在一定程度
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 课程设计 报告