我们exImageCropPicker 1.0.4

我们exImageCropPicker 1.0.4

测试已测试
语言 Obj-CObjective C
许可证 MIT
发布最后发布2018年6月

voids维护。



 
依赖
WeexSDK>= 0
QBImagePickerController~> 3.4.0
RSKImageCropper~> 2.0.0
 

  • voids

weex-image-crop-picker

JitPack CocoaPods license

由于weex market 中的 weex-image-picker 插件并没有裁剪和多选功能,看到它也是从 react-native-image-picker 搬运过来的,并且该插件原作者推荐了功能较多的 react-native-image-crop-picker ,于是产生了此项目。

Android

  • 在根目录的 build.gradle 中增加 jitpack 的地址

    allprojects {
      repositories {
        ...
        maven { url 'https://jitpack.io' }
      }
    }
  • 在您的 app 目录的 build.gradle 中增加一行依赖

    dependencies {
      compile com.github.voids:weex-image-crop-picker:1.0.2
    }
    // 如果提示duplicate entry,则exclude不需要的module,如下
    dependencies {
        compile('com.github.voids:weex-image-crop-picker:1.0.2') {
            exclude module: 'weex_sdk'
        }
    }
  • 在 Application 子类中注册 module

    import cn.dv4.weeximagecroppicker.ImageCropPickerModule;
    // 在WXSDKEngine.initialize之后注册module
    WXSDKEngine.registerModule("imageCropPicker", ImageCropPickerModule.class);
  • 在您的 WXSDKInstance 所在的 Activity 中重载 onActivityResult,否则无法接收到返回结果

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
            if (mWXSDKInstance != null) {
            mWXSDKInstance.onActivityResult(requestCode, resultCode, data);
        }
    }
  • 如果需要使用 camera,则需要在 AndroidManifest.xml 中手动添加一行权限

    <uses-permission android:name="android.permission.CAMERA"/>

iOS

  • 在 Podfile 中增加一行依赖

    pod 'WeexImageCropPicker'
    
  • 更新依赖

    pod install
  • 在 appdelegate 中注册 module

    #import <WeexImageCropPicker/ImageCropPicker.h>
    // 在[WXSDKEngine initSDKEnvironment] 之后注册module
    [WXSDKEngine registerModule:@"imageCropPicker" withClass:[ImageCropPicker class]];
  • 请在 info.plist 中自行添加权限

JavaScript

由于 weex 的扩展为 callback,不支持 promise,所以用法有所调整。

// example
var ImageCropPicker = weex.requireModule('imageCropPicker')
var options = {
    width: 300,
    height: 300,
    includeExif: true,
    mediaType: 'photo',
    cropping: true
}

export default {
    data: {
        result:""
    },
    methods: {
        gallery(e) {
            ImageCropPicker.openPicker(options, (response) => {
                // 成功返回 {code:'E_SUCCESS', data:{...}}
                this.result = JSON.stringify(response)
            })
        },
        camera(e) {
            ImageCropPicker.openCamera(options, (response) => {
                // 失败返回 {code:'E_PERMISSION_MISSING', message:'...'}
                this.result = JSON.stringify(response)
            })
        }
    }
}

options

属性 类型 描述
cropping bool (默认 false) 是否开启图片剪裁
width number 剪裁后图片的宽度,cropping为true时有效
height number 剪裁后图片的高度,cropping为true时有效
multiple bool (默认 false) 是否开启多选,开启多选后裁剪功能无效
writeTempFile (ios only) bool (默认 true) 当设置为false时,不将选择的图片写入临时文件。这对于通过includeBase64选项检索文件内容而无需从磁盘读取文件时提高性能很有用。
includeBase64 bool (默认 false) 是否输出base64
includeExif bool (默认 false) 是否输出图片exif信息,如gps、光圈、快门速度等
cropperActiveWidgetColor (android only) string (默认 "#424242") 在剪裁图片时,确定活动窗口的颜色。
cropperStatusBarColor (android only) string (默认 #424242) 在剪裁图片时,确定状态栏的颜色。
cropperToolbarColor (android only) string (默认 #424242) 在剪裁图片时,确定工具栏的颜色。
freeStyleCropEnabled (android only) bool (默认 false) 允许用户应用自定义矩形区域进行裁剪
cropperToolbarTitle string (默认 Edit Photo) 在剪裁图片时,确定工具栏的标题。
cropperCircleOverlay bool (默认 false) 是否在裁剪时开启遮罩
disableCropperColorSetters (android only) bool (默认 false) 在剪裁图片时,禁用裁剪库的颜色设置。
minFiles (ios only) number (默认 1) 使用multiple选项时,需要选择的最少文件数
maxFiles (ios only) number (默认 5) 使用multiple选项时,可选择的最多文件数
waitAnimationEnd (ios only) bool (默认 true) Promise将在ViewController completion块被调用后解决/拒绝
smartAlbums (ios only) array (支持值:['PhotoStream', 'Generic', 'Panoramas', 'Videos', 'Favorites', 'Timelapses', 'AllHidden', 'RecentlyAdded', 'Bursts', 'SlomoVideos', 'UserLibrary', 'SelfPortraits', 'Screenshots', 'DepthEffect', 'LivePhotos', 'Animated', 'LongExposure']) (默认 ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) 可供选择的智能相册列表
useFrontCamera (ios only) bool (默认 false) 是否在打开时默认使用前置/'自拍'相机
compressVideoPreset (ios only) string (默认 MediumQuality) 选择用于视频压缩的预设
compressImageMaxWidth number (默认 none) 指定图片压缩的最大宽度
compressImageMaxHeight number (默认 none) 指定图片压缩的最大高度
compressImageQuality number (默认 1) 图片压缩质量 (取值范围 0 — 1,1为最好质量)
loadingLabelText (ios only) string (默认 "Processing assets...") 在图片在选择器加载时显示的文本
mediaType string (默认 any) 媒体选择类型: 'photo'=照片, 'video'=视频, 'any'=全部
showsSelectedCount (ios only) bool (默认 true) 是否显示所选资源数量
showCropGuidelines (android only) bool (默认 true) 是否在剪裁时显示顶部3x3网格
hideBottomControls (android only) bool (默认 false) 是否显示底部控件
enableRotationGesture (android only) bool (默认 false) 是否启用手势旋转图片
cropperChooseText (ios only) string (默认 choose) 选择按钮文本
cropperCancelText (ios only) string (默认 Cancel) 取消按钮文本

参数与react-native-image-crop-picker文档中列出的参数一致

注:与原插件的android部分一样,并未实现视频压缩,因为ffmpeg太慢并且需要许可证