多媒体技术实验报告.doc

上传人:罗晋 文档编号:6078977 上传时间:2020-09-06 格式:DOC 页数:24 大小:1.12MB
返回 下载 相关 举报
多媒体技术实验报告.doc_第1页
第1页 / 共24页
多媒体技术实验报告.doc_第2页
第2页 / 共24页
多媒体技术实验报告.doc_第3页
第3页 / 共24页
多媒体技术实验报告.doc_第4页
第4页 / 共24页
多媒体技术实验报告.doc_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《多媒体技术实验报告.doc》由会员分享,可在线阅读,更多相关《多媒体技术实验报告.doc(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 java.io.IOException;import java.io.OutputStream;import

4、java.util.Scanner;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

5、.next() casepng: 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.pr

6、intln(转换完成!); break; 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.pr

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

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

9、a.awt.*;import java.awt.image.BufferedImage;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:Users14779D

10、esktop, C:Users14779Desktop, 2.jpg, 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; / 默认

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

12、tDir; public void setOutputDir(String 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) t

13、his.outputWidth = outputWidth; public 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 =

14、 new File(path); return file.length(); / 图片处理 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;

15、 int newHeight;/ 判断是否是等比缩放 if (this.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) (

16、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) 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 FileOutputStr

18、eam(outputDir + outputFileName);/ JPEGImageEncoder可适用于其他图片类型的转换/ 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 Str

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

20、Pic(String inputDir, String outputDir, String inputFileName, String outputFileName, int width, int height, boolean gp) / 输入图路径 this.inputDir = inputDir;/ 输出图路径 this.outputDir = outputDir;/ 输入图文件名 this.inputFileName = inputFileName;/ 输出图文件名 this.outputFileName = outputFileName;/ 设置图片长宽 setWidthAndHei

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

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

23、s.headx=;this.heady=;this.amp=;this.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 = func

24、tion()this.alpha+=deltaTime*0.001;var 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,t

25、his.headxi+l*this.ampi,this.headyi);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;/现在执行到哪一帧thi

26、s.babyEyeTimer=0;/计时器this.babyEyeCount=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();b

27、abyTaili.src=./img/babyTail+i+.png;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+2

28、000;/如果睁着眼睛的状态为1500-2000elsethis.babyEyeInterval=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.b

29、abyBodyTimer%=300;if(this.babyBodyCount19)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.h

30、eight*0.5);var babyBodyCount=this.babyBodyCount;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(

31、);Background.jsfunction drawBackground()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;/

32、 console.log(data.fruitNum);else if(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 (l900) baby.babyBodyCount=0;/ data.reset();mom.momBodyCount=0;data.addScore();halo.born(baby.x,baby.y);/ var A=1;/ A+;/console.log(A);Data.jsvar dataObj=function()this.fruitNum=0;/果实数量this

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1