多媒体技术实验报告_第1页
多媒体技术实验报告_第2页
多媒体技术实验报告_第3页
多媒体技术实验报告_第4页
多媒体技术实验报告_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

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

文档简介

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);还有的用来执行格式之间的代码转换 (ImageT

3、ranscoder) 和报告错误 (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.;import java.io.IOException;import java.io.OutputStream;import java.util.Scann

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

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

6、le(/Users/14779/Desktop/1(1).bmp); ImageIO.write(img, bmp, ops); System.out.println(转换完成!); break; caseGIF: casegif: ops = new (new File(/Users/14779/Desktop/1(1).gif); ImageIO.write(img, gif, ops); System.out.println(转换完成!); break; default: System.out.println(请输入正确格式!); break; catch (IOException e)

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

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

9、Exception;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, 2(2).jpg, 120, 120, false); class Co

10、mpressPicDemo private = null; / 文件对象 private String inputDir; / 输入图路径 private String outputDir; / 输出图路径 private String input; / 输入图文件名 private String output; / 输出图文件名 private int outputWidth = 100; / 默认输出图片宽 private int outputHeight = 100; / 默认输出图片高 private boolean proportion = true; / 是否等比缩放标记(默认为等

11、比缩放) public CompressPicDemo() / 初始化变量 inputDir = ; outputDir = ; input = ; output = ; outputWidth = 100; outputHeight = 100; public void setInputDir(String inputDir) this.inputDir = inputDir; public void setOutputDir(String outputDir) this.outputDir = outputDir; public void setInput(String input) th

12、is.input = input; public void setOutput(String output) this.output = output; public void setOutputWidth(int outputWidth) this.outputWidth = outputWidth; public void setOutputHeight(int outputHeight) this.outputHeight = outputHeight; public void setWidthAndHeight(int width, int height) this.outputWid

13、th = width; this.outputHeight = height; /* * 获得图片大小 * 传入参数 String path :图片路径 */ public long getPicSize(String path) file = new ); return (); / 图片处理 public String compressPic() try /获得源文件 file = new + input); if (!() return ; Image img = ImageIO.read(file);/ 判断图片格式是否正确 if (img.getWidth(null) = -1) Sy

14、stem.out.println( cant read,retry! + ); return no; else int newWidth; int newHeight;/ 判断是否是等比缩放 if (portion = true) / 为等比缩放计算输出的图片宽度及高度 double rate1 = (double) img.getWidth(null) / (double) outputWidth + 0.1; double rate2 = (double) img.getHeight(null) / (double) outputHeight + 0.1;/ 根据缩放比率大

15、的进行缩放控制 double rate = rate1 rate2 ? rate1 : rate2; newWidth = (int) (double) img.getWidth(null) / rate); newHeight = (int) (double) img.getHeight(null) / rate); else newWidth = img.getWidth(null); / 输出的图片宽度 newHeight = img.getHeight(null); / 输出的图片高度 BufferedImage tag = new BufferedImage(int) newWidt

16、h, (int) newHeight, BufferedImage.TYPE_INT_RGB);/* Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的* 优先级比速度高 生成的图片质量比较好 但速度慢*/ tag.getGraphics().drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); String formatName = (outputDir + output).substring(outputDir + output).lastIndex

17、Of(.) + 1);/ out = new (outputDir + output);/ JPEGImageEncoder可适用于其他图片类型的转换/ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);/ encoder.encode(tag); ImageIO.write(tag, formatName , new + output) );/ out.close(); catch (IOException ex) ex.printStackTrace(); return ok; public String compres

18、sPic (String inputDir, String outputDir, String input, String output) / 输入图路径 this.inputDir = inputDir;/ 输出图路径 this.outputDir = outputDir;/ 输入图文件名 this.input = input;/ 输出图文件名 this.output = output; return compressPic(); public String compressPic(String inputDir, String outputDir, String input, String

19、 output, int width, int height, boolean gp) / 输入图路径 this.inputDir = inputDir;/ 输出图路径 this.outputDir = outputDir;/ 输入图文件名 this.input = input;/ 输出图文件名 this.output = output;/ 设置图片长宽 setWidthAndHeight(width, height);/ 是否是等比缩放 标记 portion = gp; return compressPic(); 六、实验过程中的问题及对应思考实验中出现了找不到输出文件的问题

20、,后考虑到可能是文件大小关系,所以换了一个小一些的图片,完成实验实验三 超媒体开发设计一、实验目的1、熟悉超文本和超文本系统的建立和典型的外部模型;2、熟练的运用超文本标记语言的标记方法展示超媒体;3、通过运用超文本标记语言熟悉结点和链之间形成的超媒体结构。二、实验环境1、主流操作系统系统;2、主流浏览器;3、系统有文本编辑器和网站开发工具。三、实验内容1、运用超文本标识语言和可扩展语言架构Web站点的基本框架;2、练习超文本标识语言进行超媒体站点架构时的合理布局及技巧;3、Web站点主题内容不限,但必须要有一明确主题体现超媒体;4、可以用记事本编写实验代码;5、根据实验内容撰写对应的实验报告

21、;6、回答老师的对应考核提问。四、设计方案使用canvas做出一个H5小游戏主要需要实现大鱼吃果实大鱼喂小鱼小鱼恢复体力还有一定的场景和界面的五、实验代码Index.htmllovefish游戏规则鼠标控制大鱼吃果实吃到果实后喂给小鱼若无及时投喂则小鱼死亡红色果实1分蓝色果实两分RESTARTAne.jsvar aneObj = function()this.rootx = ;this.headx=;this.heady=;this.amp=;this.alpha=0;this.num = 50;/ 初始化aneOtotype.init = function()for (var i

22、 = 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;/ 绘制海葵aneOtotype.draw = function()this.alpha+=deltaTime*0.001;var l=Math.sin(this.alpha);/ctx2.save();ctx2.globalAlpha = 0.6;ctx2.strok

23、eStyle = #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);ctx2.stroke();ctx2.restore();Baby.jsvar babyObj=function()this.x;this.y

24、;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.babyEyeCount=0;/现在执行到哪一帧this.babyBodyTimer=0;/计时器this.babyBodyCount=0;/现在执行到哪一帧th

25、is.babyEyeInterval;/这张图片持续多久babyOtotype.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;for (var i = 0; i 2; i+) babyEyei=new Image();babyEyei.src=./img/babyEye

26、+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.babyEyeInterval=200;/闭眼状态默认200msif (this.babyEyeTimerthis.babyEyeInterval)

27、 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.babyBodyCount19)this.babyBodyCount=19;data.gameOver=true;ctx1.save();/属性仅适用于小鱼ctx

28、1.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.babyBodyCount;ctx1.drawImage(babyBodybabyBodyCount,-babyBodybabyBodyCount

29、.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 drawBackground()ctx2.drawImage(bgPic,0,0,canWidth,canHeight);Collision.js/碰撞检测/判断大鱼

30、和果实的距离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(fruit.fruitTypei=blue)data.double=2;elsedata.double=1;wave.born(fruit.x

31、i,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 +);/添加样式的颜色 白色 +alphactx1.fillText(GAMEOVER,w*0.5,h*0.5);ctx1.restore();dataOtot

32、ype.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 = new Image();this.blue = new Image();/果实形态2fruitOtotype.num = 30;frui

33、tOtotype.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.orange.src=./img/fruit.png;this.blue.src=./img/blue.png;/console.log(初始化执行

34、);fruitOtotype.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.spdi*5*deltaTime;/当成熟,y坐标上移(果实上漂)ctx2.drawImage(pic, this.xi- this.li *

35、 0.5,this.yi- this.li * 0.5,this.li,this.li);if (this.yi10) /当果实飘出屏外时置果实为无任务this.alivei=false; /console.log(画果实执行);fruitOtotype.born=function(i)/果实坐标依附在海葵上var aneID =Math.floor(Math.random()*ane.num);this.xi=ane.headxaneID;this.yi=ane.headyaneID;this.li=0;/长度从0开始this.alivei=true;var ran=Math.r

36、andom();/随机数随机决定蓝色和黄色果实if (ran0.3) this.fruitTypei=blue;elsethis.fruitTypei=orange;/console.log(果实出生执行);/console.log(canHeight)fruitOtotype.dead=function(i)/消失this.alivei=false;function fruitMonitor()/保证屏幕中至少有15个果实var num=0;for (var i = 0; i fruit.num; i+) if (fruit.alivei) num+;if (num15) /如果

37、活跃的果实小于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=;/半径haloOtotype.num=10;/池haloOtotype.init=function()for (var i = 0; i this.num; i+) this.alivei=false;this.ri=0;haloOtotype.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

温馨提示

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

评论

0/150

提交评论