岁月联盟 · 中国技术网 本站主页 | 安全认证 | 用户服务 | 技术论坛
新闻快报 | 新手学堂 | 黑客特区 | 程序语言 | 数 据 库 | 防 火 墙 | 路由交换 | 系统集成 | 服 务 器 | 存储备份 | 考试认证
Windows | Linux | Java | 协议分析 | 问题解答 | 进程大全 | 网页设计 | 多 媒 体 | 图库资料 | 软件下载 | 站内下载
  您现在的位置: 岁月联盟 >> Java >> 核心技术 >> JavaMedia >> Java正文
JAVA 3D动画展示图(Part2,使用QuickTime)
作者:未知 文章来源:本站整理 点击数: 更新时间:2007-7-22 17:29:58
初始化.在终止时相应的调用QTSession.close()方法.
  
  轨迹定位和媒体访问
  
  // more globalsprivate Track videoTrack;private Media vidMedia;// in the constructor, // extract the video track from the movievideoTrack =   movie.getIndTrackType(1,       StdQTConstants.videoMediaType,      StdQTConstants.movieTrackMediaType);if (videoTrack == null) { System.out.println("Sorry, not a video"); System.exit(0);}// get the media used by the video trackvidMedia = videoTrack.getMedia();
  
  一旦媒体打开,从中提取各种信息
  
  // more globalsprivate MediaSample mediaSample;private int numSamples; // number of samplesprivate int sampIdx;   // current sample indexprivate int width;    // frame widthprivate int height;   // frame height// in the constructornumSamples = vidMedia.getSampleCount();sampIdx = 1;  // get first sample in the trackmediaSample = vidMedia.getSample(0,  vidMedia.sampleNumToMediaTime(sampIdx).time,1);// store width and height of image in the sampleImageDescription imgDesc =    ImageDescription) mediaSample.description;width = imgDesc.getWidth();height = imgDesc.getHeight();
  
  sampIdx作为计数器将在抽样中被重复调用(抽样于位置1开始).
  
  动画图像的宽度和高度由第一个抽样获得,接下来所有的抽样都是同样的尺寸.
  
  测算 FPS
  
  由QTSnapper返回的 帧数/秒 将在稍后被用作类的不同使用方法的比较参数.构造器中必要的参数已被初始化.
  
  // frame rate globalsprivate long startTime;private long numFramesMade;// initialize them in the constructorstartTime = System.currentTimeMillis(); numFramesMade = 0;
  
  结束
  
  将应用程序结束时,QTSnapper类中的stopMovie()方法将被调用.它报告FPS,关闭QuickTime.
  
  // globalsprivate DecimalFormat frameDf =   new DecimalFormat("0.#"); // 1 dpsynchronized public void stopMovie(){ if (isSessionOpen) {  // report frame rate  long duration =     System.currentTimeMillis() - startTime;  double frameRate =    ((double) numFramesMade*1000.0)/duration;  System.out.println("FPS: " +          frameDf.format(frameRate));  QTSession.close(); // close down QuickTime  isSessionOpen = false; }}
  
  由于stopMovie()和getFrame()是同步的,所以从动画中提取帧和QuickTime关闭在时间上是不可能同时进行.
  
  缓存帧
  
  getFrame()返回一次抽样样品,称作BufferedImage对象.被选择的帧利用索引指数存贮在sampIdx.
  
  // globalsprivate BufferedImage img, formatImg;synchronized public BufferedImage getFrame(){ if (!isSessionOpen)  return null; if (sampIdx > numSamples)    // start back with the first sample  sampIdx = 1; try {  /* Get the sample starting at the    specified index time */  TimeInfo ti =    vidMedia.sampleNumToMediaTime(sampIdx);  mediaSample=vidMedia.getSample(0,ti.time,1);  sampIdx++;  writeToBufferedImage(mediaSample, img);  // resize img, writing it to formatImg  Graphics g = formatImg.getGraphics();  g.drawImage(img, 0, 0,     FORMAT_SIZE, FORMAT_SIZE, null);   // Overlay current

上一页  [1] [2] 


  • 上一个Java:
  • 下一个Java:
  •  
    热门文章
    推荐文章
    关于我们 | 发展历程 | 网站地图 | 广告服务 | 招贤纳士 | 战略合作 | 友情链接 | 著作声明 | 联系我们
    Copyright © 2002-2007 SYUE All rights reserved.
    E_mail:Admin@Syue.Com 皖ICP备05004589号
    未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
    传世私服 传奇世界私服 天龙八部私服 bet365 传世私服 天龙八部私服 热血江湖私服 英雄合击传奇私服 热血江湖私服 bet365 bet365