因爲weex market裏的 weex-image-picker插件並沒有裁剪和多選功能,看到也是從 react-native-image-picker移植來的,而且該插件原做者推薦了功能比較多的 react-native-image-crop-picker ,因而產生了此項目。
root目錄的build.gradle增長jitpack的地址javascript
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
在你的app目錄的build.gradle增長一行依賴java
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子類中註冊modulereact
import cn.dv4.weeximagecroppicker.ImageCropPickerModule; // 在WXSDKEngine.initialize以後註冊module WXSDKEngine.registerModule("imageCropPicker", ImageCropPickerModule.class);
在你的WXSDKInstance所在的Activity中重載onActivityResult,不然接收不到返回結果android
@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中添加一行權限ios
<uses-permission android:name="android.permission.CAMERA"/>
在Podfile增長一行依賴git
pod 'WeexImageCropPicker'
更新依賴github
pod install
appdelegate中註冊moduleobjective-c
#import <WeexImageCropPicker/ImageCropPicker.h> // 在[WXSDKEngine initSDKEnvironment] 以後註冊module [WXSDKEngine registerModule:@"imageCropPicker" withClass:[ImageCropPicker class]];
因爲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) }) } } }
Property | Type | Description |
---|---|---|
cropping | bool (default false) | 是否開啓圖片剪裁 |
width | number | 剪裁後圖片的寬度,cropping 爲true時有效 |
height | number | 剪裁後圖片的高度,cropping 爲true時有效 |
multiple | bool (default false) | 是否開啓多選,開啓多選後裁剪功能無效 |
writeTempFile (ios only) | bool (default true) | When set to false, does not write temporary files for the selected images. This is useful to improve performance when you are retrieving file contents with the includeBase64 option and don't need to read files from disk. |
includeBase64 | bool (default false) | 是否輸出base64 |
includeExif | bool (default false) | 是否輸出圖片exif信息,如gps、光圈、快門速度等 |
cropperActiveWidgetColor (android only) | string (default "#424242" ) |
When cropping image, determines ActiveWidget color. |
cropperStatusBarColor (android only) | string (default #424242 ) |
When cropping image, determines the color of StatusBar. |
cropperToolbarColor (android only) | string (default #424242 ) |
When cropping image, determines the color of Toolbar. |
freeStyleCropEnabled (android only) | bool (default false) | Enables user to apply custom rectangle area for cropping |
cropperToolbarTitle | string (default Edit Photo ) |
When cropping image, determines the title of Toolbar. |
cropperCircleOverlay | bool (default false) | 是否裁剪時開啓遮罩 |
minFiles (ios only) | number (default 1) | Min number of files to select when using multiple option |
maxFiles (ios only) | number (default 5) | Max number of files to select when using multiple option |
waitAnimationEnd (ios only) | bool (default true) | Promise will resolve/reject once ViewController completion block is called |
smartAlbums (ios only) | array (supported values: ['PhotoStream', 'Generic', 'Panoramas', 'Videos', 'Favorites', 'Timelapses', 'AllHidden', 'RecentlyAdded', 'Bursts', 'SlomoVideos', 'UserLibrary', 'SelfPortraits', 'Screenshots', 'DepthEffect', 'LivePhotos', 'Animated', 'LongExposure']) (default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) | List of smart albums to choose from |
useFrontCamera (ios only) | bool (default false) | Whether to default to the front/'selfie' camera when opened |
compressVideoPreset (ios only) | string (default MediumQuality) | Choose which preset will be used for video compression |
compressImageMaxWidth | number (default none) | 圖片壓縮指定最大寬度 |
compressImageMaxHeight | number (default none) | 圖片壓縮指定最大高度 |
compressImageQuality | number (default 1) | 圖片壓縮質量 (取值範圍 0 — 1,1爲最好質量) |
loadingLabelText (ios only) | string (default "Processing assets...") | Text displayed while photo is loading in picker |
mediaType | string (default any) | 媒體選擇類型: 'photo'=照片, 'video'=視頻, 'any'=所有 |
showsSelectedCount (ios only) | bool (default true) | Whether to show the number of selected assets |
showCropGuidelines (android only) | bool (default true) | Whether to show the 3x3 grid on top of the image during cropping |
hideBottomControls (android only) | bool (default false) | Whether to display bottom controls |
enableRotationGesture (android only) | bool (default false) | Whether to enable rotating the image by hand gesture |
參數均與 react-native-image-crop-picker 文檔中所列的參數保持一致注:跟原插件的android部份同樣,並未實現視頻壓縮,由於ffmpeg太慢而且須要licenceshell