您的位置:首页 > 移动开发 > Android开发

Android版添加phonegap--imagePicker插件教程

2015-12-29 10:42 435 查看
一、Cordova-imagePicker的介绍:

Cordova插件实现多图像选择,支持IOS和Android4及以上。

二、安装插件:

插件符合Cordova规范,也可以使用Phonegap/Cordova命令行界面安装。

phonegap plugin add https://github.com/wymsee/cordova-imagePicker.git
cordova plugin add https://github.com/wymsee/cordova-imagePicker.git
三、使用插件:

该插件创建的对象方法window.imagePicker.getPictures(成功、失败、选项)

例如:获得全尺寸图片(默认选项)

window.imagePicker.getPictures(

function(results) {

for (var i = 0; i < results.length; i++) {

console.log('Image URI: ' + results[i]);

        }

}, function (error) {

console.log('Error: ' + error);

    }

);

例如:得到10幅画的宽度为800

window.imagePicker.getPictures(

function(results) {

for (var i = 0; i < results.length; i++) {

console.log('Image URI: ' + results[i]);

        }

}, function (error) {

console.log('Error: ' + error);

}, {

maximumImagesCount: 10,

width: 800

    }

);

四、选项

options = {

//max images to be selected, defaults to 15. If this is set to 1, upon

//selection of a single image, the plugin will return it.

maximumImagesCount: int,

//max width and height to allow the images to be.  Will keep aspect

//ratio no matter what.  So if both are 800, the returned image

//will be at most 800 pixels wide and 800 pixels tall.  If the width is

//800 and height 0 the image will be 800 pixels wide if the source

//is at least that wide.

width: int,

height: int,

//quality of resized image, defaults to 100

quality: int (0-100)

};

五、安卓使用说明

插件返回的图像,存储在一个临时目录中。这些图像通常不会被自动删除。文件应该被删除或移动你的JavaScript文件。

Android这个插件使用的是MultiImageChooser修改,MultiImageChooser采用了BSD 2-Clause许可证文件中可以找到bsd_license。一些代码里面MultiImageChooser也有Apache许可证可以在文件下找到Apache_license。

imagePicker插件Demo:https://github.com/wymsee/cordova-imagePicker

KeyMob移动广告平台是中国专业的移动广告 、移动广告优化平台,为企业客户和应用开发者提供最优的技术服务, 创造最佳收入。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: