多媒体技术实验报告

上传人:dus****log 文档编号:146677836 上传时间:2022-08-31 格式:DOC 页数:24 大小:1.12MB
收藏 版权申诉 举报 下载
多媒体技术实验报告_第1页
第1页 / 共24页
多媒体技术实验报告_第2页
第2页 / 共24页
多媒体技术实验报告_第3页
第3页 / 共24页
资源描述:

《多媒体技术实验报告》由会员分享,可在线阅读,更多相关《多媒体技术实验报告(24页珍藏版)》请在装配图网上搜索。

1、江苏科技大学多媒体技术考核报告(2017/2018学年第1学期)课程名称: 多 媒 体 技 术 指导教师: 景 国 良 实验地点: 东校区外训楼软件工程实验室 学生姓名: 谢卉 学生学号: 1477965899 院 系: 计算机学院 专 业: 计算机科学与技术专业 考核得分: 2017年 11 月 日实验一 多媒体图像文件转换一、实验目的1掌握多媒体静态图像的基本概念,技术和获取过程。2掌握多媒体图像文件基本格式种类。 3掌握不同图像文件的数据结构形式,了解不同格式图像文件的具体类型区别。4运用高级语言编程实现不同图像文件类型的相互转换。二、实验环境1、主流操作系统;2、高级语言编程环境。三、

2、实验内容1、编写程序实现主流图像文件格式之间的相互转换;2、至少要实现JPG、BMP、GIF、PNG图像文件之间的转换;3、编程语言不限;4、根据实验内容撰写对应的实验报告。四、设计方案ImageIO 类的静态方法可以执行许多常见的图像 I/O 操作。此包包含一些基本类和接口,有的用来描述图像文件内容(包括元数据和缩略图)(IIOImage);有的用来控制图像读取过程(ImageReader、ImageReadParam 和 ImageTypeSpecifier)和控制图像写入过程(ImageWriter 和 ImageWriteParam);还有的用来执行格式之间的代码转换 (ImageTr

3、anscoder) 和报告错误 (IIOException)。可处理图像格式有:jpg,BMP,bmp,JPG,wbmp,jpeg,png,PNG,JPEG,WBMP,GIF,gif。另外在加一些输入代码可实现简单的格式转换选择。五、实验代码import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.io.File;import java.io.FileOutputStream;import ion;import java.io.OutputStream;import java.util.Scanne

4、r;public class Main public static void main(String args) Scanner scan = new Scanner(System.in); System.out.println(请输入需要转换的格式jpg, bmp, png, gif:); File out = new File(/Users/14779/Desktop/1.jpg); /将图片写入ImageIO流 try BufferedImage img = ImageIO.read(out); /将图片写出到指定位置(复制图片) switch (scan.next() casepng:

5、 casePNG: OutputStream ops = new FileOutputStream(new File(/Users/14779/Desktop/1(1).png); ImageIO.write(img, png, ops); System.out.println(转换完成!); break; casejpg: caseJPG: ops = new FileOutputStream(new File(/Users/14779/Desktop/1(1).jpg); ImageIO.write(img, jpg, ops); System.out.println(转换完成!); br

6、eak; casebmp: caseBMP: ops = new FileOutputStream(new File(/Users/14779/Desktop/1(1).bmp); ImageIO.write(img, bmp, ops); System.out.println(转换完成!); break; caseGIF: casegif: ops = new FileOutputStream(new File(/Users/14779/Desktop/1(1).gif); ImageIO.write(img, gif, ops); System.out.println(转换完成!); br

7、eak; default: System.out.println(请输入正确格式!); break; catch (IOException e) e.printStackTrace(); 实验截图六、实验过程中的问题及对应思考ImageIO是一个封装好的图像输入输出类, 使用 ImageIO 类的静态方法可以执行许多常见的图像 I/O 操作。我将图片路径事先写好放入程序里,可以通过键入转换格式来达到想要转换到的格式,为了避免键入出错,我将主程序写在try函数中。 实验二 多媒体图像文件压缩一、实验目的1、了解各种图像文件格式之间的存储方法和方式,了解其编码的组织方式;2、掌握运用高级编程语言编

8、写多媒体应用程序的方法;3、运用高级编程语言实现对多媒体图像文件的压缩的方法。二、实验环境1、主流操作系统;2、高级语言编程环境。三、实验内容1、使用高级编程语言编写良好的运行界面;2、运用高级编程语言编写核心代码实现对图像文件的压缩;3、了解压缩过程中的顺进和累进方法的运用提高压缩比;4、合理的考虑压缩算法压缩和解压的速度平衡;5、编程语言不限;6、根据实验内容撰写对应的实验报告。四、设计方案使用imagioIO的对图片的压缩处理来进行此项实验。五、实验代码package pany;import IO;import java.awt.*;import java.awt.image.Buffe

9、redImage;import java.io.File;import java.io.IOException;public class Main public static void main(String args) CompressPicDemo mypic = new CompressPicDemo(); System.out.println(输入的图片大小: + mypic.getPicSize(C:Users14779Desktop2.jpg)/1024 + KB); pressPic(C:Users14779Desktop, C:Users14779Desktop, 2.jpg,

10、 2(2).jpg, 120, 120, false); class CompressPicDemo private File file = null; / 文件对象 private String inputDir; / 输入图路径 private String outputDir; / 输出图路径 private String inputFileName; / 输入图文件名 private String outputFileName; / 输出图文件名 private int outputWidth = 100; / 默认输出图片宽 private int outputHeight = 10

11、0; / 默认输出图片高 private boolean proportion = true; / 是否等比缩放标记(默认为等比缩放) public CompressPicDemo() / 初始化变量 inputDir = ; outputDir = ; inputFileName = ; outputFileName = ; outputWidth = 100; outputHeight = 100; public void setInputDir(String inputDir) this.inputDir = inputDir; public void setOutputDir(Stri

12、ng outputDir) this.outputDir = outputDir; public void setInputFileName(String inputFileName) this.inputFileName = inputFileName; public void setOutputFileName(String outputFileName) this.outputFileName = outputFileName; public void setOutputWidth(int outputWidth) this.outputWidth = outputWidth; publ

13、ic void setOutputHeight(int outputHeight) this.outputHeight = outputHeight; public void setWidthAndHeight(int width, int height) this.outputWidth = width; this.outputHeight = height; /* * 获得图片大小 * 传入参数 String path :图片路径 */ public long getPicSize(String path) file = new File(path); return file.length

14、(); / 图片处理 public String compressPic() try /获得源文件 file = new File(inputDir + inputFileName); if (!file.exists() return ; Image img = ImageIO.read(file);/ 判断图片格式是否正确 if (img.getWidth(null) = -1) System.out.println( cant read,retry! + ); return no; else int newWidth; int newHeight;/ 判断是否是等比缩放 if (this

15、.proportion = true) / 为等比缩放计算输出的图片宽度及高度 double rate1 = (double) img.getWidth(null) / (double) outputWidth + 0.1; double rate2 = (double) img.getHeight(null) / (double) outputHeight + 0.1;/ 根据缩放比率大的进行缩放控制 double rate = rate1 rate2 ? rate1 : rate2; newWidth = (int) (double) img.getWidth(null) / rate);

16、 newHeight = (int) (double) img.getHeight(null) / rate); else newWidth = img.getWidth(null); / 输出的图片宽度 newHeight = img.getHeight(null); / 输出的图片高度 BufferedImage tag = new BufferedImage(int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB);/* Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的* 优先级比速度高 生成的图片质量

17、比较好 但速度慢*/ tag.getGraphics().drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); String formatName = (outputDir + outputFileName).substring(outputDir + outputFileName).lastIndexOf(.) + 1);/ FileOutputStream out = new FileOutputStream(outputDir + outputFileName);/ J

18、PEGImageEncoder可适用于其他图片类型的转换/ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);/ encoder.encode(tag); ImageIO.write(tag, formatName , new File(outputDir + outputFileName) );/ out.close(); catch (IOException ex) ex.printStackTrace(); return ok; public String compressPic (String inputDir, S

19、tring outputDir, String inputFileName, String outputFileName) / 输入图路径 this.inputDir = inputDir;/ 输出图路径 this.outputDir = outputDir;/ 输入图文件名 this.inputFileName = inputFileName;/ 输出图文件名 this.outputFileName = outputFileName; return compressPic(); public String compressPic(String inputDir, String outputD

20、ir, String inputFileName, String outputFileName, int width, int height, boolean gp) / 输入图路径 this.inputDir = inputDir;/ 输出图路径 this.outputDir = outputDir;/ 输入图文件名 this.inputFileName = inputFileName;/ 输出图文件名 this.outputFileName = outputFileName;/ 设置图片长宽 setWidthAndHeight(width, height);/ 是否是等比缩放 标记 thi

21、s.proportion = gp; return compressPic(); 六、实验过程中的问题及对应思考实验中出现了找不到输出文件的问题,后考虑到可能是文件大小关系,所以换了一个小一些的图片,完成实验实验三 超媒体开发设计一、实验目的1、熟悉超文本和超文本系统的建立和典型的外部模型;2、熟练的运用超文本标记语言的标记方法展示超媒体;3、通过运用超文本标记语言熟悉结点和链之间形成的超媒体结构。二、实验环境1、主流操作系统系统;2、主流浏览器;3、系统有文本编辑器和网站开发工具。三、实验内容1、运用超文本标识语言和可扩展语言架构Web站点的基本框架;2、练习超文本标识语言进行超媒体站点架构

22、时的合理布局及技巧;3、Web站点主题内容不限,但必须要有一明确主题体现超媒体;4、可以用记事本编写实验代码;5、根据实验内容撰写对应的实验报告;6、回答老师的对应考核提问。四、设计方案使用canvas做出一个H5小游戏主要需要实现大鱼吃果实大鱼喂小鱼小鱼恢复体力还有一定的场景和界面的五、实验代码Index.htmllovefish游戏规则鼠标控制大鱼吃果实吃到果实后喂给小鱼若无及时投喂则小鱼死亡红色果实1分蓝色果实两分RESTARTAne.jsvar aneObj = function()this.rootx = ;this.headx=;this.heady=;this.amp=;this

23、.alpha=0;this.num = 50;/ 初始化aneObj.prototype.init = function()for (var i = 0; i this.num; i+) this.rootxi = i * 20 + Math.random()*20;this.headxi=this.rootxi;this.headyi=canHeight-200+Math.random()*50;this.ampi=Math.random()*50+50;/ 绘制海葵aneObj.prototype.draw = function()this.alpha+=deltaTime*0.001;v

24、ar l=Math.sin(this.alpha);/ctx2.save();ctx2.globalAlpha = 0.6;ctx2.strokeStyle = #3b154e;ctx2.lineWidth = 20;ctx2.lineCap = round;for (var i = 0; i this.num; i+) /ctx2.beginPath();ctx2.moveTo(this.rootxi,canHeight);ctx2.quadraticCurveTo(this.rootxi,canHeight - 80,this.headxi+l*this.ampi,this.headyi)

25、;ctx2.stroke();ctx2.restore();Baby.jsvar babyObj=function()this.x;this.y;this.angle;/this.babyEye=new Image();/this.babyBody=new Image();/this.babyTail=new Image();/ this.babyTail=;/尾巴数组/ this.babyEye=;/眼睛数组this.babyTailTimer=0;/计时器this.babyTailCount=0;/现在执行到哪一帧this.babyEyeTimer=0;/计时器this.babyEyeCo

26、unt=0;/现在执行到哪一帧this.babyBodyTimer=0;/计时器this.babyBodyCount=0;/现在执行到哪一帧this.babyEyeInterval;/这张图片持续多久babyObj.prototype.init=function()this.x=canWidth*0.5-50;this.y=canHeight*0.5+50;this.angle=0;/console.log(this.y);for(var i=0;i8;i+)/初始化小鱼尾巴数组babyTaili=new Image();babyTaili.src=./img/babyTail+i+.png;

27、for (var i = 0; i 2; i+) babyEyei=new Image();babyEyei.src=./img/babyEye+i+.png;for (var i = 0; i 50) this.babyTailCount=(this.babyTailCount+1)%8;this.babyTailTimer%=50;/this.babyEyeTimer+=deltaTime;if (this.babyEyeCount=0) this.babyEyeInterval=Math.random()*1500+2000;/如果睁着眼睛的状态为1500-2000elsethis.ba

28、byEyeInterval=200;/闭眼状态默认200msif (this.babyEyeTimerthis.babyEyeInterval) this.babyEyeCount=(this.babyEyeCount+1)%2;/取模实现循环this.babyEyeTimer%=this.babyEyeInterval;/this.babyBodyTimer+=deltaTime;if (this.babyBodyTimer300)this.babyBodyCount=this.babyBodyCount+1;this.babyBodyTimer%=300;if(this.babyBodyC

29、ount19)this.babyBodyCount=19;data.gameOver=true;ctx1.save();/属性仅适用于小鱼ctx1.translate(this.x,this.y);/指定相对原点值ctx1.rotate(this.angle);var babyTailCount=this.babyTailCount;ctx1.drawImage(babyTailbabyTailCount,-babyTailbabyTailCount.width*0.5+23,-babyTailbabyTailCount.height*0.5);var babyBodyCount=this.b

30、abyBodyCount;ctx1.drawImage(babyBodybabyBodyCount,-babyBodybabyBodyCount.width*0.5,-babyBodybabyBodyCount.height*0.5);var babyEyeCount=this.babyEyeCount;ctx1.drawImage(babyEyebabyEyeCount,-babyEyebabyEyeCount.width*0.5,-babyEyebabyEyeCount.height*0.5);ctx1.restore();Background.jsfunction drawBackgro

31、und()ctx2.drawImage(bgPic,0,0,canWidth,canHeight);Collision.js/碰撞检测/判断大鱼和果实的距离function momFruitsCollision()if (data.gameOver) return;for (var i = 0; i fruit.num; i+) if (fruit.alivei) /距离的平方var l=calLength2(fruit.xi,fruit.yi,mom.x,mom.y);if (l7)mom.momBodyCount=7;/ console.log(data.fruitNum);else if

32、(fruit.fruitTypei=blue)data.double=2;elsedata.double=1;wave.born(fruit.xi,fruit.yi);/ console.log(mom.momBodyCount);function momBabyCollision()if(data.fruitNum0&!data.gameOver)var l=calLength2(mom.x,mom.y,baby.x,baby.y);if (l1) this.alpha=1;ctx1.fillStyle=rgba(255,255,255,+ this.alpha +);/添加样式的颜色 白色

33、 +alphactx1.fillText(GAMEOVER,w*0.5,h*0.5);ctx1.restore();dataObj.prototype.addScore=function()this.score+=this.fruitNum*this.double;this.fruitNum=0;this.double=1;Fruit.jsvar fruitObj=function()this.alive = ;/boolthis.x = ;/this.y = ;/this.l=;/图片长度this.spd=;/速度this.fruitType=;/分辨果实类型this.orange = ne

34、w Image();this.blue = new Image();/果实形态2fruitObj.prototype.num = 30;fruitObj.prototype.init=function()for (var i = 0; i this.num; i+) this.alivei=false;/初始化果实为激活状态this.xi=0;this.yi=0;this.spdi=Math.random()*0.017+0.003;/随机生成速度在0.003,0.02之间this.fruitTypei=0;this.born(i);/console.log(this.yi); this.or

35、ange.src=./img/fruit.png;this.blue.src=./img/blue.png;/console.log(初始化执行);fruitObj.prototype.draw=function()/画果实for (var i = 0; i this.num; i+) if (this.alivei) if (this.fruitTypei=blue) var pic =this.blue;elsevar pic=this.orange;if(this.li=15)/判断成熟this.li+=this.spdi*deltaTime;/循环变大elsethis.yi-=this

36、.spdi*5*deltaTime;/当成熟,y坐标上移(果实上漂)ctx2.drawImage(pic, this.xi- this.li * 0.5,this.yi- this.li * 0.5,this.li,this.li);if (this.yi10) /当果实飘出屏外时置果实为无任务this.alivei=false; /console.log(画果实执行);fruitObj.prototype.born=function(i)/果实坐标依附在海葵上var aneID =Math.floor(Math.random()*ane.num);this.xi=ane.headxaneID

37、;this.yi=ane.headyaneID;this.li=0;/长度从0开始this.alivei=true;var ran=Math.random();/随机数随机决定蓝色和黄色果实if (ran0.3) this.fruitTypei=blue;elsethis.fruitTypei=orange;/console.log(果实出生执行);/console.log(canHeight)fruitObj.prototype.dead=function(i)/消失this.alivei=false;function fruitMonitor()/保证屏幕中至少有15个果实var num=

38、0;for (var i = 0; i fruit.num; i+) if (fruit.alivei) num+;if (num15) /如果活跃的果实小于15,则送入新的果实sendFruit();return;function sendFruit()/送果实for (var i = 0; i fruit.num; i+) if (!fruit.alivei) fruit.born(i);return;Halo.jsvar haloObj=function()this.x=;this.y=;this.alive=;/状态this.r=;/半径haloObj.prototype.num=10

39、;/池haloObj.prototype.init=function()for (var i = 0; i this.num; i+) this.alivei=false;this.ri=0;haloObj.prototype.draw=function()for (var i = 0; i 50) this.alivei=false;var alpha=1-this.ri/50;ctx1.beginPath();ctx1.arc(this.xi,this.yi,this.ri,0,2*Math.PI);ctx1.closePath();ctx1.strokeStyle=rgba(237,10

40、9,0,+alpha+); /添加样式的颜色 白色 +alphactx1.stroke();ctx1.restore();haloObj.prototype.born=function(x,y)for(var i=0;ithis.num;i+)if (!this.alivei) /若它是死的,则可以出生this.alivei=true;/更改状态this.ri=10;/半径 this.xi=x;this.yi=y;return;/出生之后跳出来Main.jsvar can1;var can2;var ctx1;var ctx2;var canWidth;var canHeight;var la

41、stTime;var deltaTime;var bgPic= new Image();var ane;/海葵var fruit;/果实var mom/大鱼var baby;var babyTail=;/尾巴数组var babyEye=;/眼睛数组var babyBody=;/身体数组var bigTail=;var bigEye=;/眼睛数组var data;var wave;var halo;var momBodyOra = ;var momBodyBlue=;document.body.onload=game;function game()lastTime=Date.now();delt

42、aTime=0;init();gameloop();function init()/初始化工作/获得canvas contextcan1 = document.getElementById(canvas1);ctx1 = can1.getContext(2d);can2 = document.getElementById(canvas2);can1.addEventListener(mousemove,onMouseMove,false);ctx2 = can2.getContext(2d);bgPic.src=./img/background.jpg;canWidth =can1.width;canHeight=can1.height;

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!