首页 文章 精选 留言 我的

精选列表

搜索[表单生成],共10000篇文章
优秀的个人博客,低调大师

android为视频、音乐、图片等生成缩略图

1、Video 对于视频,取第一帧作为缩略图,也就是怎样从filePath得到一个Bitmap对象。 private Bitmap createVideoThumbnail(String filePath) { Bitmap bitmap = null; MediaMetadataRetriever retriever = new MediaMetadataRetriever();try { retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY); retriever.setDataSource(filePath); bitmap = retriever.captureFrame(); } catch(IllegalArgumentException ex) {// Assume this is a corrupt video file } catch (RuntimeException ex) {// Assume this is a corrupt video file. } finally {try { retriever.release(); } catch (RuntimeException ex) {// Ignore failures while cleaning up. } }return bitmap; }Android提供了MediaMetadataRetriever,由JNI(media_jni)实现。 看得出MediaMetadataRetriever主要有两个功能:MODE_GET_METADATA_ONLY和MODE_CAPTURE_FRAME_ONLY 这里设mode为MODE_CAPTURE_FRAME_ONLY,调用captureFrame取得一帧。 另外还有两个方法可以用: extractMetadata 提取文件信息,ARTIST、DATE、YEAR、DURATION、RATING、FRAME_RATE、VIDEO_FORMAT 和extractAlbumArt 提取专辑信息,这个下面的音乐文件可以用到。2、Music 对于音乐,取得AlbumImage作为缩略图,还是用MediaMetadataRetriever private Bitmap createAlbumThumbnail(String filePath) { Bitmap bitmap = null; MediaMetadataRetriever retriever = new MediaMetadataRetriever();try { retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); retriever.setDataSource(filePath);byte[] art = retriever.extractAlbumArt(); bitmap = BitmapFactory.decodeByteArray(art, 0, art.length); } catch(IllegalArgumentException ex) { } catch (RuntimeException ex) { } finally {try { retriever.release(); } catch (RuntimeException ex) {// Ignore failures while cleaning up. } }return bitmap; } retriever.extractAlbumArt()得到的是byte数组,还需要一步用BitmapFactory编码得到Bitmap对象。3、Image 图片就很简单了 Bitmap bm = null; Options op = new Options(); op.inSampleSize = inSampleSize; op.inJustDecodeBounds = false; bm = BitmapFactory.decodeFile(mFile.getPath(), op); 复制代码能直接得到Bitmap对象,把图片缩小到合适大小就OK。 同样上面的Video和Music,retrive到Bitmap后也需要缩小处理。 本文转自java豆子博客园博客,原文链接:http://www.cnblogs.com/error404/archive/2011/08/17/2142971.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册