




已阅读5页,还剩36页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C#.NET课程设计实验报告班级:计算机1302 姓名:吴秀文 学号:201320100218 题目:简易图像编辑与制作软件的实现目的:(1) 采用C#制作一个简易的图像编辑与制作软件,巩固C#的知识。(2) 培养学生独立完成C#项目的开发经验。任务要求:(1) 图像编辑:1) 打开要编辑的图片,并显示初始图像:包括从菜单的“打开”项,工具栏“打开”按钮和系统打开方式(即在我的电脑里,选中图片文件后,右建打开方式选择本软件打开图片),以及拖放打开方式(即将图片拖动到打开的软件界面,就将该图打开显示)四种打开图片的功能均需实现。2) 显示功能:图像放大,缩小,实际大小3) 图像编辑:水平翻转,垂直翻转,顺时针旋转90度,逆时针旋转90度,反色,浮雕,黑白,柔化,锐化,灰度化,雾化,马赛克效果,设置图像像素大小。(2) 图片制作:1) 新建图像;2) 绘制直线,弧线,曲线,空心矩形,实心矩形,空心椭圆,实心椭圆,多边形,实心多边形,文本;3) 线型设置:实线,虚线,线条粗细,线条始止端点的形状4) 颜色设置:设置线或实心形状或字体的颜色,包括纯色(solidbrush);渐变色(渐变画笔);设置纹理(阴影画笔);设置填充图片(纹理画笔)(3) 保存:对新建的图像,保存时选择路径,图片格式,文件名,然后保存。否则直接保存图象。(4) 另存为:选择路径,图片格式,文件名,然后保存图像。(5) 菜单和工具栏:软件需要有菜单和工具栏快捷按钮,菜单包括所有功能,工具栏可以设置最常用的快捷按钮以上是软件需要实现的基本功能,但可以自行新增一些功能和绘制图形。对于保存和打开图片功能,一般可设置支持BMP,JPG,PNG,GIF,TIFF,ICON格式。实验步骤:1、前期工作1.1新建Windows应用程序项目:wuxiuwen,重命名form1,wxw_Form1.cs。1.2 界面制作1.3 添加主界面form类的数据成员 private Bitmap img = null; private string fullname = null;/图像文件完整路径 private int tempWidth, tempHeight;/图像变化信息,宽高属性 private Color c;/前景色 Color c1;/纯色;或渐变色的始止颜色;或者纹理的前景色和背景色 private Color startcolor, endcolor;/用户设置前景色与背景色 DashStyle line_type; /线型 LineCap StartCap, EndCap;/起始端点形状,结束端点形状 int colortype;/1 纯色,2 渐变色,3 纹理,4 图片填充 LinearGradientMode lgm;/渐变方向 HatchStyle hs; /纹理类型 Bitmap fill_img;/填充图片 int lineheight;/线宽 Pen pen;/钢笔 SolidBrush sb;/纯色画笔 LinearGradientBrush lgb;/渐变画笔 HatchBrush hb;/阴影画笔,可画纹理效果 TextureBrush tb;/纹理画笔,可用于图片填充 int drawselect = 0;/绘制图形选项,1直线,2曲线,3弧线 4空心矩形,5实心矩形,6 空心椭圆,7实心椭圆,8空心多边形,9实心多边形,10 文本 Point startpoint;/绘制的起始点 Point targetPoint;/终点 bool domousemove = false;/ 判断标记,是否为绘制时的鼠标移动 ArrayList arrayPoint = new ArrayList();/存放绘制过程中的多个点的动态数组 string drawstring = ; /绘制的文本 Font myfont = new Font(宋体, 12);/绘制文本的字体1.4 设置属性 public int ImageWidth/图片宽构造函数 get return img.Width; set tempWidth = value; public int ImageHeight/图片高构造函数 get return img.Height; set tempHeight = value; public Color startColor/前景色属性设置函数 get return c; set c = value; public Color commonColor /纯色;或渐变色的始止颜色;或者纹理的前景色和背景色 get return c1; set c1 = value; public int ColorType get return colortype; set colortype = value; public Color StartColor /前景色 get return startcolor; set startcolor = value; public Color EndColor/背景色 get return endcolor; set endcolor = value; public HatchStyle HS/纹理样式 get return hs; set hs = value; public const int Rotate180FlipY = 0;/水平旋转 public const int Rotate180FlipX = 1; /垂直旋转 public const int Rotate90FlipNone = 2;/顺时针 public const int Rotate270FlipNone = 3; /逆时针旋转901.5 主界面 Form1_Load方法中进行数据的必要初始化操作 c = Color.Blue; c1 = Color.Green; line_type = DashStyle.Solid; startcolor = Color.Yellow; endcolor = Color.Green; colortype = 1; StartCap = LineCap.NoAnchor; EndCap = LineCap.NoAnchor; lgm = LinearGradientMode.Horizontal; hs = HatchStyle.DashedHorizontal; img = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(img); sb = new SolidBrush(Color.White); g.FillRectangle(sb, 0, 0, pictureBox1.Width, pictureBox1.Height); pictureBox1.Image = img; if (fullname != null & !fullname.Equals() Bitmap tempImage = new Bitmap(fullname); img = new Bitmap(tempImage.Width, tempImage.Height); Graphics draw = Graphics.FromImage(img); draw.DrawImage(tempImage, 0, 0, tempImage.Width, tempImage.Height); pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox1.Image = img; draw.Dispose(); tempImage.Dispose(); 添加系统命名空间using System.Collections;using System.Drawing.Imaging;using System.Drawing.Drawing2D;2、图像编辑2.1点击菜单栏的打开 /增加带参数的构造方法 public wxw_Form1(string a) InitializeComponent(); fullname = a; private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = bmp,jpg,gif,png,tiff,icon|*.bmp;*.jpg;*.gif;*.png;*.tiff;*.icon; dialog.Title = 选择图片; if (dialog.ShowDialog() = DialogResult.OK) Bitmap tempImage = new Bitmap(dialog.FileName); img = new Bitmap(tempImage.Width, tempImage.Height); Graphics draw = Graphics.FromImage(img); draw.DrawImage(tempImage, 0, 0, tempImage.Width, tempImage.Height); fullname = dialog.FileName.ToString(); pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox1.Image = img; draw.Dispose(); tempImage.Dispose(); 2.2 图像显示功能2.2.1图像实际大小显示:Dock必须设置为None,否则图像放大与缩小将失效 private void 实际大小ToolStripMenuItem_Click(object sender, EventArgs e) pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; 2.2.2放大图像的显示比例 private void 放大ToolStripMenuItem_Click(object sender, EventArgs e) pictureBox1.Height = (int)Math.Ceiling(pictureBox1.Height * 1.1); pictureBox1.Width = (int)Math.Ceiling(pictureBox1.Width * 1.1); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; 2.2.3 缩小图像的显示比例 private void 缩小ToolStripMenuItem_Click(object sender, EventArgs e) pictureBox1.Height = (int)Math.Ceiling(pictureBox1.Height * 0.9); pictureBox1.Width = (int)Math.Ceiling(pictureBox1.Width * 0.9); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; 2.3图像编辑2.3.1设置图像像素大小新建图像编辑界面:wxw_setsize_Form1.cs private wxw_Form1 sizeForm; /确认按钮 private void button1_Click(object sender, EventArgs e) if (myWidthTB.Text.Equals() | myHeightTB.Text.Equals() MessageBox.Show(高度与宽度不能为空, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); return; sizeForm.ImageWidth = int.Parse(myWidthTB.Text.ToString(); sizeForm.ImageHeight = int.Parse(myHeightTB.Text.ToString(); this.Close(); /取消按钮 private void button2_Click(object sender, EventArgs e) this.Close(); private void wxw_setsize_Form1_Load(object sender, EventArgs e) sizeForm = (wxw_Form1)this.Owner; currWidthLabel.Text = sizeForm.ImageWidth.ToString(); currHeightLabel.Text = sizeForm.ImageHeight.ToString(); 在主程序中添加代码 private void 图像大小设置ToolStripMenuItem_Click(object sender, EventArgs e) if (img = null) MessageBox.Show(未打开任何图片, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; tempWidth = img.Width;/赋值给宽的全局变量 tempHeight = img.Height;/赋值给高的全局变量 wxw_setsize_Form1 sizeForm = new wxw_setsize_Form1(); sizeForm.Owner = this; sizeForm.ShowDialog(); if (tempHeight != img.Height | tempWidth != img.Width) Bitmap tempImage = new Bitmap(tempWidth, tempHeight); Graphics draw = Graphics.FromImage(tempImage); draw.DrawImage(img, 0, 0, tempImage.Width, tempImage.Height); img = tempImage; pictureBox1.Image = img; pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; 2.3.2翻转设置private void convertBitmap(int rotate180FlipY) if (img = null) MessageBox.Show(未打开任何图片, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); return; tempWidth = img.Width;/赋值给宽的全局变量 tempHeight = img.Height;/赋值给高的全局变量 Bitmap tempImage = new Bitmap(tempWidth, tempHeight); Graphics draw = Graphics.FromImage(tempImage); switch (rotate180FlipY) case Rotate180FlipY: /水平旋转 img.RotateFlip(RotateFlipType.Rotate180FlipY); break; case Rotate180FlipX: /垂直翻转 img.RotateFlip(RotateFlipType.Rotate180FlipX); break; case Rotate90FlipNone: /顺时针翻转 img.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case Rotate270FlipNone: /逆时针翻转 img.RotateFlip(RotateFlipType.Rotate270FlipNone); break; draw.DrawImage(img, 0, 0, tempImage.Width, tempImage.Height); img = tempImage; pictureBox1.Image = img; pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; 2.3.3 水平翻转设置 private void 水平翻转ToolStripMenuItem_Click(object sender, EventArgs e) this.convertBitmap(Rotate180FlipY); 2.3.4 垂直翻转 private void 垂直翻转ToolStripMenuItem_Click(object sender, EventArgs e) this.convertBitmap(Rotate180FlipX); 2.3.5顺时针旋转 private void 顺时针旋转90度ToolStripMenuItem_Click(object sender, EventArgs e) this.convertBitmap(Rotate90FlipNone); 2.3.6逆时针旋转 private void 逆时针旋转90度ToolStripMenuItem_Click(object sender, EventArgs e) this.convertBitmap(Rotate90FlipNone); 3、 图片制作3.1 新建图像private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) img = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(img); sb = new SolidBrush(Color.White); g.FillRectangle(sb, 0, 0, pictureBox1.Width, pictureBox1.Height); pictureBox1.Image = img; 3.2 绘制工具取消绘制private void toolStripButton18_Click(object sender, EventArgs e) drawselect = 0; this.Cursor = Cursors.Default; 绘制直线private void toolStripButton19_Click(object sender, EventArgs e) drawselect = 1; this.Cursor = Cursors.Cross; 弧线private void toolStripButton21_Click(object sender, EventArgs e) drawselect = 3; this.Cursor = Cursors.Cross; 曲线 private void toolStripButton20_Click(object sender, EventArgs e) drawselect = 1; this.Cursor = Cursors.Cross; 空心矩形 private void toolStripButton22_Click(object sender, EventArgs e) drawselect = 4; this.Cursor = Cursors.Cross; 实心矩形private void toolStripButton23_Click(object sender, EventArgs e) drawselect = 5; this.Cursor = Cursors.Cross; 空心椭圆 private void toolStripButton24_Click(object sender, EventArgs e) drawselect = 6; this.Cursor = Cursors.Cross; 实心椭圆private void toolStripButton25_Click(object sender, EventArgs e) drawselect = 7; this.Cursor = Cursors.Cross; 空心多边形private void toolStripButton26_Click(object sender, EventArgs e) drawselect = 8; this.Cursor = Cursors.Cross; 实心多边形private void toolStripButton27_Click(object sender, EventArgs e) drawselect = 9; this.Cursor = Cursors.Cross; 文本 private void toolStripButton28_Click(object sender, EventArgs e) drawselect = 10; this.Cursor = Cursors.Cross; 绘制需要绘制工具与鼠标配合using System.Drawing.Drawing2D;namespace wuxiuwen / 鼠标状态类型 public enum MouseStateType MouseDown, MouseMove, MouseUp class ToolUtils /绘制多边形 public static void DrawPolygon(Graphics g, Point p, Boolean isFill, Pen pen, Color c) GraphicsPath tempGraphicsPath = new GraphicsPath(); if (p.Length 1) tempGraphicsPath.AddLines(p.ToArray(); if (isFill) g.FillPath(new SolidBrush(c), tempGraphicsPath); g.DrawPath(pen, tempGraphicsPath); 鼠标的点击、移动、双击等操作 / 鼠标双击 private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e) if (domousemove = false) return; pictureBox1.Image = this.img; Graphics g = Graphics.FromImage(pictureBox1.Image); pen = new Pen(c, float.Parse(toolStripComboBox1.Text); pen.DashStyle = line_type; pen.StartCap = StartCap; pen.EndCap = EndCap; switch (drawselect) case 2: /曲线 arrayPoint.RemoveAt(arrayPoint.Count - 1); Point drawPoint = new PointarrayPoint.Count; int i = 0; foreach (Point p in arrayPoint) drawPointi+ = p; g.DrawCurve(pen, drawPoint); break; case 3: /弧线 if (arrayPoint.Count 4) return; arrayPoint.RemoveAt(arrayPoint.Count - 1); Point drawPoint = new PointarrayPoint.Count; int i = 0; foreach (Point p in arrayPoint) drawPointi+ = p; g.DrawBezier(pen, drawPoint0, drawPoint1, drawPoint2, drawPoint3); break; case 8: /空心多边形 arrayPoint.RemoveAt(arrayPoint.Count - 1); Point drawPoint = new PointarrayPoint.Count; int i = 0; foreach (Point p in arrayPoint) drawPointi+ = p; ToolUtils.DrawPolygon(g, drawPoint, false, pen, c); break; case 9: /实心多边形 arrayPoint.RemoveAt(arrayPoint.Count - 1); Point drawPoint = new PointarrayPoint.Count; int i = 0; foreach (Point p in arrayPoint) drawPointi+ = p; ToolUtils.DrawPolygon(g, drawPoint, true, pen, c); break; domousemove = false; drawselect = 0; this.Cursor = Cursors.Default; arrayPoint.Clear(); g.Dispose(); /按下鼠标 private void pictureBox1_MouseDown(object sender, MouseEventArgs e) if (drawselect = 0) return; startpoint = new Point(e.X, e.Y); targetPoint = new Point(e.X, e.Y); arrayPoint.Add(startpoint);/起点加入点阵数组 domousemove = true;/绘制图形开始 pictureBox1.Image = (Bitmap)this.img.Clone(); Graphics g = Graphics.FromImage(pictureBox1.Image); switch (drawselect) case 10: if (alphaTextBox.Visible) for (int i = 0; i alphaTextBox.Lines.Length; +i) Point newLocation = new Point(alphaTextBox.Location.X, alphaTextBox.Location.Y + i * (alphaTextBox.Font.Height - 5); g.DrawString(alphaTextBox.Linesi, alphaTextBox.Font, new SolidBrush(Color.FromArgb(255, alphaTextBox.ForeColor), newLocation); alphaTextBox.Text = ; alphaTextBox.Visible = false; else alphaTextBox.Location = startpoint; alphaTextBox.ForeColor = c; alphaTextBox.Font = new Font(alphaTextBox.Font.FontFamily, 22, alphaTextBox.Font.Style); alphaTextBox.Visible = true; break; /鼠标拖动 private void pictureBox1_MouseMove(object sender,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 邢台汇文分班考试题目及答案
- 九年级半期考试题及答案
- 护理查房考试题及答案
- 2025教资科二考试真题及答案
- 化验室基础知识简答考试题及答案
- 温岭二中考试试卷真题及答案
- 广西安全员B证考试题及答案
- 延津县期中考试卷及答案
- 计算机ms一级考试试题及答案
- 口腔护理溶液作用、疾病预防及护理要点知识试题附答案
- 页人音版三年级音乐上册音乐教案(2025-2026学年)
- 员工应急救护知识培训课件
- 2025昆明中北交通旅游(集团)有限责任公司驾驶员招聘(60人)考试参考题库及答案解析
- 2026中国航空工业集团金航数码校园招聘备考考试题库附答案解析
- 健康教育培训师资队伍建设方案
- 二类医疗器械零售经营备案质量管理制度
- 2025年医技三基考试试题及答案
- 既有建筑幕墙安全培训课件
- 2025年全国事业单位联考C类《职业能力倾向测验》试题及答案
- 厂区安全行走培训内容课件
- 中国原发性闭角型青光眼诊治方案专家共识(2025年)解读
评论
0/150
提交评论