C#设计报告 俄罗斯方块_第1页
C#设计报告 俄罗斯方块_第2页
C#设计报告 俄罗斯方块_第3页
C#设计报告 俄罗斯方块_第4页
C#设计报告 俄罗斯方块_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

0 项目实训报告书项目实训报告书 学生姓名 课程名称 C 课程设计 题 目 俄罗斯方块 专业班级 指导教师 完成日期 1 目录目录 一 概述一 概述 2 2 1 11 1 背景背景 2 2 1 21 2 开发与运行环境开发与运行环境 3 3 二 需求分析二 需求分析 3 3 三 系统设计三 系统设计 4 4 四 详细设计四 详细设计 5 5 4 14 1 界面设计界面设计 5 5 4 24 2 代码设计代码设计 7 7 五 结束语五 结束语 25 25 六 参考文献六 参考文献 26 26 2 1 概述概述 1 1背景背景 俄罗斯方块 由莫斯科科学学院程序员 Alexei Pajitnov 所设计 该游戏最 初是作为自我消遣的电脑游戏而被制作出来的 此后 由于政治和经济等多方 面的原因 该游戏曾经被多家公司代理过 经过多轮诉讼的争夺后 该游戏的代 理权最终还是被任天堂获得 俄罗斯方块对于任天堂来说意义重大 因为将它 与 GB 搭配在一起后 产生了令人意想不到的效果 获得了巨大的成功 而对 于中国玩家来说 俄罗斯方块可以说是第一次让国人认识到游戏是一种老少皆 宜的娱乐方式 从某种程度上扭转了国人的 游戏是小孩子的东西 或 游戏是毒 害儿童的元凶 等错误观念 一个最初的版本是 Spectrum Holobyte 为 IBM 兼容 机开发的游戏 该游戏是一款休闲智力型 与通常的此类游戏相比 这款游戏新增了在模 块样式上的多彩性 还抛掉了以前那种枯燥的背景音乐 可以让自己随心所欲 的背景音乐 于此同时还可以让自己开动脑筋来设计模块 还可以凭自己的喜 好 可以设置画布的大小 1 2开发与运行环境开发与运行环境 系统的运行对于运行环境的要求是 硬件环境 目前 我们所开发的系统主要应用在中小规模的学校内部 因此 一般配置的计算机 硬件就可以满足系统需求 考虑到学校规模的扩大和硬件价格的降低 为本系统配置在较 优秀的服务器硬件上 可以充分发挥本系统的性能 处理器 Intel Pentium 4 3 06 GX 或更高 内存 256M 推荐 硬盘空间 40GB 显卡 SVGA 显示适配器 软件环境 操作系统 Windows 2000 XP 开发软件 Microsoft Visual Studio NET 2003 数据库 Microsoft SQL Server 2000 3 2 课程设计的目的和意义课程设计的目的和意义 俄罗斯方块游戏是一个经典的小游戏 由于它简单有趣 因而得到了广泛的流行 男 女老幼都适合 而俄罗斯方块游戏的设计工作复杂且富有挑战性 它包含的内容多 涉及 的知识广泛 与图形界面联系较大 包括界面的显示与更新 数据收集 音乐处理等 在 设计的过程中 必将运用到各方面的知识 这对于 C 设计者而言 是个很好的锻炼机会 2 1 实验步骤 实验步骤 1 需求分析 设计一个用户可参与 有背景音乐 可由用户控制任意暂停 可计时 可计分的俄罗斯方块游戏 2 概要设计 一个游戏运行界面 计分面板 开始按扭 暂停按扭 3 详细设计 对整个设计进行总体分析如下 1 定义 7 种砖块的类型 用两个 4 4 的二维数组来表示 2 在屏幕上用一个 10 20 表示游戏区域 3 上下左右的出界问题的考虑 3 砖块的变形问题 4 砖块的移动 向左向右向下 问题 5 满一行后消掉砖块 6 记分问题 7 用开始按扭启动游戏 8 暂停按扭暂停游戏 9 界面的设定 10 背景音乐的加入 3 3 系统功能设计系统功能设计 玩游戏前先要设置参数 键盘的设置比如说 左键 右键 下 4 键 快速向下键 顺时针旋转 逆时针旋转 环境的设置也非常重 要 比如 水平格子数 垂直格子数 格子数 前景色等 再者就 是砖块的设置 砖块是自己设计的 但是系统也有默认砖块 都是 最常用的模块 还可以改变模块的颜色 本系统主要设计以下几种 功能 1 方块下落 变形功能 在整个俄罗斯方块游戏中 方块的设计是核心 这里设计了一个方块类 Square 用来生成方块以及实现块的左移 右移 向下 变形 重画 同步显示 初始化新块等 2 自动升级功能 当分数累积到一定大小时 系统将自动为玩家提高难度 这里设置了每消除 10 行方块 就增加一级难度 当难度增加的时候 方块会相应地改变颜色 以作为对玩家的提示 3 游戏音乐功能 游戏开始音乐就自动播放 游戏暂停与结束时音乐相应消除 总控模块 输入模块处理模块输出模块 图 片 处 理 图 片 另 存 为 打 开 文 件 夹 添 加 屏 幕 抓 图 截 图 控 制 窗 口 5 图 1 系统功能模块结构图 3 以以系统功能设计分析系统功能设计分析 俄罗斯方块游戏根据功能的不同 设置了如下 12 个类 Square Command GameArea GameSetting GameOver Help ImagePanel JieMian MyPanel MyTimer PlayMidi WinListener 每个类的描述如下 1 Square 方块类 这个类中定义了生成方块的方法 用二维数组 int pattern 存放 7 种方块的四种状态 在构造方法中以随机的形式生成方块 同时提供了以下几种方法 reset leftTurn leftMove rightMove fallDown assertValid int t int s int row int col dispBlock int s 分别实现方块的重画 翻转 左移 右移 下落 同步显示等功能 2 Command 处理控制类 这是一个实现 ActionListener 接口的类 主要处理点击按钮事 件 类中定义了三个 int 型变量 button play button quit button pause 和一个 boolean 型的变量 pause resume 并赋值 在 GameArea 类中通过事件响应 在按钮执行方法中调 用其值 使用 switch 语句 根据不同按钮不同的值 来响应不同的事件 3 GameArea 游戏界面类 GameArea 继承了 JFrame 是俄罗斯方块的主要游戏界面 这个类定义了 GameSetting 类的 gameScr 对象和 ImagePanel 类的 imagepanel 对象作为游戏 区域面板和控制区域面板 在游戏区域 主要是根据相应格子的设置标志来显示相应的图 形图片 这样就实现了俄罗斯方块的实时显示 4 GameSetting 游戏画布类 这个类生成的对象将作为游戏界面的方块下落区域 画布的 设置为 15 行 10 列 当中的方格边长为 30 类中还定义了一个二维数组 int scrArr 作为 屏幕数组 表示每一个方格 游戏区域中每一个方格是否存在游戏方块是由该方格的值来 决定的 如果该方格的值为 1 则表示该方格中存在游戏方块 如果该方格中的值为 0 则 表示该方格中不存在游戏方块 因此二维数组用于记录游戏区域中每个小方格的值 此外 类中还定义了画方块的方法 根据不同的难度画出不同颜色的方块 单击 Play 按钮时 系 统调用 initScr 方法 初始化屏幕 将屏幕数组清零 当满足满行删除的条件时 系统调 用 deleteFullLine 方法 进行删行加分 而且每删除十行 难度自动增加一级 方块颜色 改变 并在难度显示框中相应显示 图 3 8 系统功能模块结构图 6 5 GameOver 游戏结束弹出提示框类 当游戏结束时 系统弹出提示 包括玩家分数以 及询问玩家要继续游戏还是退出 6 Help 帮助类 在游戏界面 按 F1 键 弹出提示窗口 获取帮助 7 ImagePanel 背景图片类 这个类继承了 JPanel 类 用来作为游戏界面中控制区域的容 器 并添加图片 8 JieMian 主界面类 这个类继承了 JPanel 类 作为游戏的第一个界面 也是难度选择 界面 定义了 9 个单选按钮 当玩家未选任何难度就按 Enter 时 系统会弹出一个提示框 提示玩家先选难度再进入 9 MyPanel 重写 MyPanel 类 使 Panel 的四周留空间 10 MyTimer 定时线程类 类中定义了一个 run 方法 用 sleep 函数实现方块下 落的快慢 即调节难度 11 PlayMidi 添加音乐类 在游戏过程中添加背景音乐 12 WinListener 关闭窗口类 4 4 1 界面设计界面设计 1 图片浏览器主界面如下图 2 图 2 软件主界面图 7 2 参数设置如下图 3 图 3 设置图 3 图片调整界如图 4 4 2 代码设计代码设计 1 输入模块 输入模块 1 1 从文件夹中打开需要浏览的图片从文件夹中打开需要浏览的图片 openImage private void openImage 如果当前正显示幻灯片 先关闭定时器2 this timer1 Enabled false if this openFileDialog1 ShowDialog DialogResult OK 8 if this pictureBox1 Image null this pictureBox1 Image Dispose pictureBox1 Image Image FromFile this openFileDialog1 FileName 设置全局变量entireFilePath 用于保存文件名 在上一张 下一张 幻灯片显示 时记录当前 图片的位置 this entireFilePath this openFileDialog1 FileName ToString this statusBarPanel2 Text 图片大小 this pictureBox1 Image Size Width ToString this statusBarPanel2 Text this pictureBox1 Image Size Height ToString 得到图片所在文件夹的路径 string filePath filePath openFileDialog1 FileName Substring 0 openFileDialog1 FileName LastIndexOf 打开目录 并将目录中所有 jpg bmp gif类型的图片放入FileInDir集合 System IO DirectoryInfo dir new System IO DirectoryInfo filePath System IO FileInfo fileInfo dir GetFiles FileInDir Clear foreach FileInfo fi in fileInfo if fi Extension JPG fi Extension jpg fi Extension jpeg fi Extension tif fi Extension png fi Extension bmp fi Extension BMP fi Extension gif fi Extension GIF FileInDir Add fi FullName ToString 得到当前打开图片在FileInDir中的索引 index为定义的全局变量 for index 0 index 1 确定图片浏览的上一张和下一张按钮的可用性 this toolBarButton7 Enabled true if index 0 当索引值为第一章时上一张按钮不可用 this toolBarButton5 Enabled false this toolBarButton6 Enabled true 9 else if index FileInDir Count 1 this toolBarButton6 Enabled false this toolBarButton5 Enabled true else this toolBarButton5 Enabled true this toolBarButton6 Enabled true this statusBarPanel1 Text this openFileDialog1 FileName ToString 在 状态栏显示浏览图片的路径 FileInfo info new FileInfo this openFileDialog1 FileName ToString this statusBarPanel3 Text 文件大小 info Length ToString B 显示图片文件的大小 从文件夹中拖进图片框 这里用到两个事件 从文件夹中拖进图片框 这里用到两个事件 DragDrop DragDrop 和和 DragEnter DragEnter private void pictureBox1 DragEnter object sender System Windows Forms DragEventArgs e 图片拖进图片框 if e Data GetDataPresent DataFormats FileDrop e Effect DragDropEffects Link else e Effect DragDropEffects None private void pictureBox1 DragDrop object sender System Windows Forms DragEventArgs e 拖进后释放鼠标 if e Data GetDataPresent DataFormats FileDrop string files string e Data GetData DataFormats FileDrop for int i 0 i files Length i test files i 抓屏和截图 这里的代码用到了抓屏和截图 这里的代码用到了 APIAPI 函数 这是一段从网上找来的代码改的 函数 这是一段从网上找来的代码改的 在抓屏这个功能中关键代码如下在抓屏这个功能中关键代码如下 this Visible false IntPtr dc1 CreateDC DISPLAY null null IntPtr null 获取屏幕句柄 即源显示设备句柄 10 Graphics g1 Graphics FromHdc dc1 MyImage new Bitmap Screen PrimaryScreen Bounds Width Screen PrimaryScreen Bounds Height g1 初始化Bitbmp实例 Graphics g2 Graphics FromImage MyImage Visible false dc1 g1 GetHdc IntPtr dc2 g2 GetHdc 获取Bitbmp实例对应的句柄 BitBlt dc2 0 0 Screen PrimaryScreen Bounds Width Screen PrimaryScreen Bounds Height dc1 0 0 13369376 利用Bitblt函数 把当前屏幕拷贝到创建的Bitbmp实例中 g1 ReleaseHdc dc1 g2 ReleaseHdc dc2 this Visible true this SetBounds 0 0 pictureBox1 Width this pictureBox1 Height this Cursor Cursors Cross this pictureBox1 Image MyImage 截图功能代码如下 截图功能代码如下 private void Form3 MouseDown object sender System Windows Forms MouseEventArgs e if isDoubleClick begin true if StartedCrop false DeltaX 0 DeltaY 0 StartedCrop true StartPoint new Point e X e Y SelectRect Width 0 SelectRect Height 0 SelectRect X e X SelectRect Y e Y Invalidate private void Form3 MouseMove object sender System Windows Forms MouseEventArgs e if begin Form thisform Form sender if StartedCrop 11 DeltaX e X StartPoint X if DeltaX 0 DeltaX 0 DeltaY e Y StartPoint Y if DeltaY 0 DeltaY 0 ControlPaint DrawReversibleFrame thisform RectangleToScreen SelectRect Color Black FrameStyle Dashed SelectRect Width e X SelectRect X SelectRect Height e Y SelectRect Y ControlPaint DrawReversibleFrame thisform RectangleToScreen SelectRect Color Black FrameStyle Dashed private void Form3 MouseUp object sender System Windows Forms MouseEventArgs e StartedCrop false SelectRect X e X StartPoint X SelectRect Y e Y StartPoint Y 鼠标截图的区域 this Cursor Cursors Cross isDoubleClick true private void Form3 KeyUp object sender System Windows Forms KeyEventArgs e 响应键盘按下Esc退出 按下Enter则截图 switch e KeyCode case Keys Escape this Close break case Keys Enter Qscreen break private void Form3 Load object sender System EventArgs e 在抓屏后在对抓去的图片全屏并进行截图 IntPtr dc1 CreateDC DISPLAY null null IntPtr null 获取屏幕句柄 即源显示设备句柄 Graphics g1 Graphics FromHdc dc1 MyImage new Bitmap Screen PrimaryScreen Bounds Width Screen PrimaryScreen Bounds Height g1 初始化Bitbmp实例 12 Graphics g2 Graphics FromImage MyImage Visible false dc1 g1 GetHdc IntPtr dc2 g2 GetHdc 获取Bitbmp实例对应的句柄 BitBlt dc2 0 0 Screen PrimaryScreen Bounds Width Screen PrimaryScreen Bounds Height dc1 0 0 13369376 利用Bitblt函数 把当前屏幕拷贝到创建的Bitbmp实例中 g1 ReleaseHdc dc1 g2 ReleaseHdc dc2 this Visible true this SetBounds 0 0 Screen PrimaryScreen Bounds Width Screen PrimaryScreen Bounds Height this Cursor Cursors Cross 鼠标为十字型鼠标 private void Form3 Paint object sender System Windows Forms PaintEventArgs e if MyImage null e Graphics DrawImage MyImage ClientRectangle 0 0 MyImage Width MyImage Height GraphicsUnit Pixel private void Form3 DoubleClick object sender System EventArgs e this Left 0 this Top 0 Bitmap theImage new Bitmap DeltaX DeltaY Graphics g Graphics FromImage theImage Rectangle destRect new Rectangle 0 0 DeltaX DeltaY g DrawImage MyImage destRect StartPoint X StartPoint Y theImage Width theImage Height GraphicsUnit Pixel 利用DrawImage方法实现对源图片的截取 MyImage Bitmap theImage Clone this SetBounds 0 0 MyImage Width MyImage Height 根据捕获的图片设定窗体的边界 this Cursor Cursors Cross Invalidate MyImage Save C Captured jpg MessageBox Show 已经保存为C Captured jpg this pictureBox1 Image MyImage this Close 2 2 处理模块 处理模块 13 2 12 1 图片文件管理 报考对图片的打开 保存 另存为 和软件的退出 代图片文件管理 报考对图片的打开 保存 另存为 和软件的退出 代 码如下 码如下 private void menuItem3 Click object sender System EventArgs e 保存图片在C盘且图片文件名为Captured jpg if this pictureBox1 Image null this pictureBox1 Image Save C Captured jpg FileInDir index ToString MessageBox Show 已经保存为C Captured jpg FileInDir index ToString else MessageBox Show 没有要保存的图片 private void menuItem4 Click object sender System EventArgs e 图片另存为 if this pictureBox1 Image null this saveFileDialog1 Filter 图像文件 JPG JPG 图像文件 BMP BMP 图像 文件 GIF GIF 图像文件 PNG PNG 所有文件 this saveFileDialog1 ShowDialog string StrFileName this saveFileDialog1 FileName if saveFileDialog1 ShowDialog DialogResult OK 文件名 if StrFileName Trim return this pictureBox1 Image Save StrFileName else MessageBox Show 没有要保存的图片 2 22 2 对图片浏览并进行放大缩小 关键代码如下 对图片浏览并进行放大缩小 关键代码如下 private void viewImage bool mark 如果图片框中当前有显示图片时才可进行该方法 if this pictureBox1 Image null 如是mark值为 1 则向前显示 if mark if index 0 MessageBox Show 这是第一张了 14 index FileInDir Count 1 else this pictureBox1 Image Image FromFile FileInDir index ToString 图片框中加载按索引显示图片 VbycView rad shiheView 如果为1 则向后显示 else if index FileInDir Count 1 MessageBox Show 这是最后一张 index 0 else this pictureBox1 Image Image FromFile FileInDir index ToString rad VbycView shiheView 按合适的显示方式显示在图片框中 entireFilePath2 FileInDir index ToString this statusBarPanel1 Text FileInDir index ToString FileInfo info new FileInfo this statusBarPanel1 Text this statusBarPanel3 Text 文件大小 info Length ToString B 显示滚动图片的文件大小 else MessageBox Show 请先打开图片 private void preView 上一张图片 this pictureBox1 Image Dispose 释放图片框占用的资源 viewImage false 15 private void nextView 下一张图片 this pictureBox1 Image Dispose viewImage true private void max 放大图片 int w pictureBox1 Image Width 图片的宽 int h pictureBox1 Image Height 图片的高 int b w h w w 25 h h 20 NewBitmap new Bitmap this pictureBox1 Image w h int this numericUpDown1 Value int this numericUpDown2 Value 新建位图并显示 在图片框中 this pictureBox1 Image NewBitmap private void min 缩小图片 int w pictureBox1 Image Width int h pictureBox1 Image Height int b w h w w 25 h h 20 NewBitmap new Bitmap this pictureBox1 Image w h this pictureBox1 Image NewBitmap 将改变后的位图显示在图片框中 2 32 3 对图片进行幻灯片播放 此关键功能包括对图片的动态显示 背景音乐播对图片进行幻灯片播放 此关键功能包括对图片的动态显示 背景音乐播 放 和自动浏览 关键代码如下 放 和自动浏览 关键代码如下 动态效果的函数 动态效果的函数 private void rad 随机出现动态显示 string aa 1 2 3 4 5 6 7 Random rr new Random string bb aa rr Next 0 aa Length switch bb 建立一个随机数组 并随机运行图片动态显示的函数 case 1 utdView break case 2 rtlView break case 3 16 lblsView break case 4 ksView break case 5 fzView break case 6 VbycView break case 7 HbycView break private void HbycView 水平百叶窗方式显示 MyBitmap Bitmap this pictureBox1 Image Clone int dh MyBitmap Height 30 int dw MyBitmap Width Graphics g this pictureBox1 CreateGraphics g Clear Color Gray Point MyPoint new Point 30 for int y 0 y 30 y MyPoint y X 0 MyPoint y Y y dh Bitmap bitmap new Bitmap MyBitmap Width MyBitmap Height for int i 0 i dh i for int j 0 j 30 j for int k 0 k dw k bitmap SetPixel MyPoint j X k MyPoint j Y i MyBitmap GetPixel MyPoint j X k MyPoint j Y i this pictureBox1 Refresh this pictureBox1 Image bitmap System Threading Thread Sleep 50 17 private void VbycView 垂直百叶窗显示图像 MyBitmap Bitmap this pictureBox1 Image Clone int dw MyBitmap Width 50 int dh MyBitmap Height Graphics g this pictureBox1 CreateGraphics 创建一个Graphics对象 g Clear Color Gray 清除整个绘图面 并以灰色填充为背景色 Point MyPoint new Point 50 for int x 0 x 50 x MyPoint x Y 0 MyPoint x X x dw Bitmap bitmap new Bitmap MyBitmap Width MyBitmap Height 处理由像素数据定义 的图像 for int i 0 i dw i for int j 0 j 50 j for int k 0 k dh k bitmap SetPixel MyPoint j X i MyPoint j Y k MyBitmap GetPixel MyPoint j X i MyPoint j Y k 指定位图像素的颜色 this pictureBox1 Refresh this pictureBox1 Image bitmap System Threading Thread Sleep 50 阻塞线程指定的时间 private void rtlView 从左到右的显示 int iWidth this pictureBox1 Width 图像宽度 int iHeight this pictureBox1 Height 图像高度 取得Graphics对象 Graphics g this pictureBox1 CreateGraphics g Clear Color Gray 初始为全灰色 for int x 0 x iWidth x x 2 g DrawImage this pictureBox1 Image 0 0 x iHeight 18 private void utdView 从上到下拉伸显示 int iWidth this pictureBox1 Width 图像宽度 int iHeight this pictureBox1 Height 图像高度 取得Graphics对象 Graphics g this pictureBox1 CreateGraphics g Clear Color Gray 初始为全灰色 for int y 0 y iHeight y g DrawImage this pictureBox1 Image 0 0 iWidth y private void ksView 四周扩散显示 int iWidth this pictureBox1 Width 图像宽度 int iHeight this pictureBox1 Height 图像高度 取得Graphics对象 Graphics g this pictureBox1 CreateGraphics g Clear Color Gray 初始为全灰色 for int x 0 x iWidth 2 x Rectangle DestRect new Rectangle iWidth 2 x iHeight 2 x 2 x 2 x Rectangle SrcRect new Rectangle 0 0 this pictureBox1 Image Width this pictureBox1 Image Height g DrawImage this pictureBox1 Image DestRect SrcRect GraphicsUnit Pixel private void fzView 反转图像 int iWidth this pictureBox1 Width 图像宽度 int iHeight this pictureBox1 Height 图像高度 取得Graphics对象 Graphics g this pictureBox1 CreateGraphics g Clear Color Gray 初始为全灰色 for int x iWidth 2 x iWidth 2 x Rectangle DestRect new Rectangle 0 iHeight 2 x iWidth 2 x Rectangle SrcRect new Rectangle 0 0 this pictureBox1 Image Width this pictureBox1 Image Height g DrawImage this pictureBox1 Image DestRect SrcRect GraphicsUnit Pixel 19 private void lblsView 两边拉伸显示 int iWidth this pictureBox1 Width 图像宽度 int iHeight this pictureBox1 Height 图像高度 取得Graphics对象 Graphics g this pictureBox1 CreateGraphics g Clear Color Gray 初始为全灰色 for int y 0 y iWidth 2 y Rectangle DestRect new Rectangle iWidth 2 y 0 2 y iHeight Rectangle SrcRect new Rectangle 0 0 this pictureBox1 Image Width this pictureBox1 Image Height g DrawImage this pictureBox1 Image DestRect SrcRect GraphicsUnit Pixel 背景音乐的代码 这里得应用背景音乐的代码 这里得应用 DirectxDirectx 控件 控件 private string filterText Audio Files wav mpa mp2 mp3 wma wav mpa mp2 mp3 wma MIDI Files mid midi rmi mid midi rmi All Files private Audio ourAudio null double ourfileLen 0 设置媒体大小的变量 private void OpenFile if ourAudio null ourAudio Stop ourAudio null OpenFileDialog ofdOpen new OpenFileDialog ofdOpen Filter filterText ofdOpen Title 打开媒体文件 string filename this openFileDialog1 FileName if ofdOpen ShowDialog DialogResult OK this textBox2 Text ofdOpen FileName OpenFileDialog ofdOpen new OpenFileDialog ofdOpen Filter filterText ofdOpen Title 打开媒体文件 if ofdOpen FileName null ourAudio Ending new System EventHandler this ClipEnded ourfileLen ourAudio Duration ourAudio Play else ourAudio Open ofdOpen FileName true catch MessageBox Show 这个文件不能被打开 无效的文件 MessageBoxButtons OK MessageBoxIcon Information 2 42 4 图片的滤镜效果和图片的滤镜效果和 private void fsView 以反色方式显示图像 int Height this pictureBox1 Image Height int Width this pictureBox1 Image Width Bitmap bitmap new Bitmap Width Height Bitmap MyBitmap Bitmap this pictureBox1 Image Color pixel for int x 1 x Width x for int y 1 y Height y int r g b pixel MyBitmap GetPixel x y r 255 pixel R g 255 pixel G b 255 pixel B bitmap SetPixel x y Color FromArgb r g b this pictureBox1 Image bitmap 21 private void fdView 以浮雕方式显示图像 int Height this pictureBox1 Image Height int Width this pictureBox1 Image Width Bitmap bitmap new Bitmap Width Height Bitmap MyBitmap Bitmap this pictureBox1 Image Color pixel1 pixel2 for int x 0 x Width 1 x for int y 0 y255 r 255 if r255 g 255 if g255 b 255 if b 0 b 0 bitmap SetPixel x y Color FromArgb r g b this pictureBox1 Image bitmap private void hbView 以黑白方式显示图像 int Height this pictureBox1 Image Height int Width this pictureBox1 Image Width Bitmap bitmap new Bitmap Width Height Bitmap MyBitmap Bitmap this pictureBox1 Image Color pixel for int x 0 x Width x for int y 0 yg r g Result Result b Result b break case 2 加权平均值法 Result int 0 7 r int 0 2 g int 0 1 b break bitmap SetPixel x y Color FromArgb Result Result Result this pictureBox1 Image bitmap private void rhView 以柔化方式显示图像 int Height this pictureBox1 Image Height int Width this pictureBox1 Image Width Bitmap bitmap new Bitmap Width Height Bitmap MyBitmap Bitmap this pictureBox1 Image Color pixel 高斯模板 int Gauss 1 2 1 2 4 2 1 2 1 for int x 1 x Width 1 x for int y 1 y Height 1 y int r 0 g 0 b 0 int Index 0 int a 0 for int col 1 col 1 col for int row 1 row255 255 r r r255 255 g g g255 255 b b b 0 0 b bitmap SetPixel x 1 y 1 Color FromArgb r g b this pictureBox1 Image bitmap private void whView 以雾化方式显示图像 int Height this pictureBox1 Image Height int Width this pictureBox1 Image Width Bitmap bitmap new Bitmap Width Height Bitmap MyBitmap Bitmap this pictureBox1 Image Color pixel for int x 1 x Width 1 x for int y 1 y Width dx Width 1 if dy Height dy Height 1 pixel MyBitmap GetPixel dx dy b

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论