利用thumbnailer API来提取图标视频或专辑的thumbnail
来源:互联网 发布:巴赫旧约德语知乎 编辑:程序博客网 时间:2024/05/29 18:30
最近我读了一篇关于thumbnailer API的文章.这个API主要是用来让我们提取图片,视频,或在线音乐的图片的thumbnail的.基于这个API我也做了一个很小的测试程序.在今天的例程中,我们选择使用"QtQuick App with QML UI (qmake)"模版来实现这个例程.这主要的原因在于以后我们的SDK有可能不再继续支持"qmlproject"模版了.基于这个模版,我做了一些的改动,从而可以使得我们的Main.qml不一定要位于qrc的资源文件中:
main.cpp
#include <QGuiApplication>#include <QQmlApplicationEngine>#include <QQuickView>int main(int argc, char *argv[]){ QGuiApplication app(argc, argv); QQuickView view;// view.setSource(QUrl(QStringLiteral("qrc:///Main.qml"))); view.setSource(QUrl::fromLocalFile("thumbnailer/Main.qml")); view.setResizeMode(QQuickView::SizeRootObjectToView); view.show(); return app.exec();}
从上面的代码中可以看出来,我们使用了一个本地的Main.qml而不是资源文件中的Main.qml.这样的改变是为了我们能够更好地使用本地的一些照片.我们在项目的.pro文件中也做了相应的修改.
我们的测试代码非常简单:
Main.qml
import QtQuick 2.3import Ubuntu.Components 1.2import Ubuntu.Thumbnailer 0.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "thumbnailer.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ // automaticOrientation: false width: units.gu(60) height: units.gu(85) function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } Page { title: i18n.tr("thumbnailer") Image { source: "image://thumbnailer/"+Qt.resolvedUrl("images/image2.jpg") width:parent.width/2 height:parent.height/2 fillMode:Image.PreserveAspectFit sourceSize:Qt.size(width, height) anchors.centerIn: parent } }}
运行我们的代码:
可能很多的开发者觉得不以为然,因为这个展示太不给力了.但是如果你的应用中有很多的这样的照片,那么对你的应用显示所展示的效率将是很大地提高.比如你有一个ListView,每个里面都放有很多的类似的照片.一个thunmbnail的照片所需要的内存和一个完整的照片所需要的内存,显然是不一样的.
我们也可以对我们项目里的一个视频做展示:
Main.qml
import QtQuick 2.3import Ubuntu.Components 1.2import Ubuntu.Thumbnailer 0.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "thumbnailer.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ // automaticOrientation: false width: units.gu(60) height: units.gu(85) function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } Page { title: i18n.tr("thumbnailer") Image { width:parent.width/2 height:parent.height/2 source: "image://thumbnailer/"+Qt.resolvedUrl("videos/sample.mp4") fillMode:Image.PreserveAspectFit sourceSize:Qt.size(width, height) anchors.centerIn: parent } }}
我们也可以的对7-digital页面的多媒体进行访问:
import QtQuick 2.3import Ubuntu.Components 1.2import Ubuntu.Thumbnailer 0.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "thumbnailer.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ // automaticOrientation: false width: units.gu(60) height: units.gu(85) function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } Page { title: i18n.tr("thumbnailer") Image { width:parent.width/2 height:parent.height/2 source: "image://albumart/album=Blur:+The+Best+Of&artist=Blur" fillMode:Image.PreserveAspectFit sourceSize:Qt.size(width, height) anchors.centerIn: parent } }}
我们也可以对音乐家及专辑进行搜索:
Main.qml
import QtQuick 2.3import Ubuntu.Components 1.2import Ubuntu.Thumbnailer 0.1/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "thumbnailer.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ // automaticOrientation: false width: units.gu(60) height: units.gu(85) function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } Page { title: i18n.tr("thumbnailer") Image { width:parent.width/2 height:parent.height/2 source: "image://artistart/"+"album=Real+Gone&artist=Tom+Waits" fillMode:Image.PreserveAspectFit sourceSize:Qt.size(width, height) anchors.centerIn: parent } }}
目前测试针对中国歌手的测试还不是很成功,比如:
source: "image://artistart/"+encode_utf8("album=传奇&artist=王菲")
整个项目的源码在:https://github.com/liu-xiao-guo/thumbnailer
0 0
- 利用thumbnailer API来提取图标视频或专辑的thumbnail
- 利用公共api提取任意网站favicon.ico图标
- WIN API-VFP提取文件中(图标资源)的图标
- android 获取.thumbnail文件下的小图标
- 实现Thumbnail Toolbars,对最小化任务栏的图标点击按钮
- IOS/OSX下利用AVFoundation来dump提取视频解码裸数据详解,提供源码
- 利用FFmpeg合成视频、提取视频帧
- 利用注册表来修改桌面的ie图标
- 视频专辑:Hibernate 视频
- C++ GDI+提取系统文件或文件夹的图标,保存为透明图片
- 视频的提取
- Excel2013利用图标集在单元格内加上各式各样的图标来表示状态
- 基于Metronic的Bootstrap开发框架经验总结(4)--Bootstrap图标的提取和利用
- 提取exe文件的图标
- 利用ffmpeg提取视频中的图片
- 利用ffmpeg来合并视频
- 利用Chrome浏览器的缓存保存音乐或视频
- 利用ffmpeg来进行视频解码的完整示例代码
- crontab文件的含义
- linux系统封装为iso
- HTML标签
- 属性的校验
- ios 的 字段、方法、属性的访问权限控制
- 利用thumbnailer API来提取图标视频或专辑的thumbnail
- Activity启动的工作过程知识点
- AndroidManifest.xml文件详解(service)
- PyLucene学习之三
- centos挂载NTFS移动硬盘
- 继承LinearLayout实现大众点评标题和图表的效果
- Struts2的类型转换及输入校验(数组类型的使用)
- 九章算法4:动态规划I
- Activity的启动模式