概述
一款針對Android平臺下的圖片選擇器,支持從相冊獲取圖片、視頻、音頻&拍照,支持裁剪(單圖or多圖裁剪)、壓縮、主題自定義配置等功能,支持動態獲取權限&適配Android 5.0+系統的開源圖片選擇框架。
支持Uniapp和Uniapp X下的Vue2、VUe3編譯,支持所有Android主流操作系統,兼容行可靠穩定
功能說明
下載源碼
一. 參數說明
參數 | 默認值 | 說明 |
---|---|---|
selectMimeType | 0 | 全部0 圖片1 視頻1 硬盤3 |
language | 0 | 系統默認 -1; 簡體中文 0; 繁體 1; 英語 2; 韓語 3; 德語 4; 法語 5; 日語 6; 越語 7; 西班牙語 8; 葡萄牙語 9; 阿拉伯語 10; 俄語 11; 捷克 12; 哈薩克斯坦 13; |
isCompress | true | 是否壓縮 |
isCrop | false | 是否剪切 |
isCameraIntercept | true | 是否攔截相機按鈕 |
isCameraForegroundService | true | 是否在前臺運行 |
isDisplayCamera | true | 是否顯示相機 |
isPageStrategy | true | 是否開啟分頁策略 |
maxSelectNum | 9 | 最大選擇數量 |
minSelectNum | 0 | 最小選擇數量 |
isVideoPauseResumePlay | true | 視頻支持暫停與播放 |
isQuickCapture | true | 使用系統攝像機錄制后,是否支持使用系統播放器立即播放視頻 |
isPreviewAudio | true | 是否支持音頻預覽 |
isPreviewImage | true | 是否支持預覽圖片 |
isPreviewVideo | true | 是否支持預覽視頻 |
isPreviewFullScreenMode | true | 是否支持全屏預覽 |
isEmptyResultReturn | true | 是否支持未選擇返回 |
isWithSelectVideoImage | true | 是否支持視頻圖片同選 |
isSelectZoomAnim | true | 選擇縮略圖縮放效果 |
isOpenClickSound | true | 是否開啟點擊音效 |
isCameraAroundState | true | 是否開啟相機前后切換 |
isCameraRotateImage | true | 拍照是否糾正旋轉圖片 |
isGif | true | 是否顯示gif文件 |
isWebp | true | 是否顯示webp文件 |
isBmp | true | 是否顯示bmp文件 |
isMaxSelectEnabledMask | true | 達到最大選擇數是否開啟禁選蒙層 |
isSyncCover | true | isPageModel模式下是否強制同步封面,默認false |
isAutomaticTitleRecyclerTop | true | 點擊相冊標題是否快速回到第一項 |
isAutoVideoPlay | true | 預覽視頻是否自動播放 |
isLoopAutoVideoPlay | true | 預覽視頻是否循環播放 |
isFilterSizeDuration | true | 是否過濾圖片或音視頻大小時長為0的資源 |
isFastSlidingSelect | true | 是否快速滑動選擇 |
isDirectReturnSingle | true | 是否直接返回單選 |
isPageSyncAlbumCount | true | 分頁模式下設置過濾條件后是否同步專輯下資源的數量 |
isUseSystemVideoPlayer | true | 是否使用系統自帶的視頻播放器 |
二. 返回數據說明
返回數據 | 數據類型 | 說明 |
---|---|---|
compressed | boolean | 是否壓縮 |
compressPath | srtring | 壓縮路徑;設置了isCompress;時返回; |
fileName | srtring | 文件名 |
maxSelectEnabledMask | boolean | 是否有最大數量限制 |
num | int | 文件數量 |
bucketId | int | |
mimeType | srtring | 文件類型 |
duration | int | 文件時長 |
cropResultAspectRatio | int | 剪切寬高比 |
path | srtring | 原圖path,但在Android Q版本上返回的是content:// Uri類型 |
checked | boolean | 是否選中 |
realPath | srtring | 絕對路徑 |
id | int | |
toSandboxPath | boolean | 是否使用自定義輸出路徑 |
sandboxPath | srtring | 自定義輸出路徑 |
chooseModel | int | |
width | int | 寬度 |
height | int | 高度 |
original | boolean | 是否開啟原圖 |
availablePath | srtring | |
cut | boolean | 是否剪切 |
cutPath | srtring | 裁剪后path,設置了isCrop返回 |
cropImageWidth | int | 剪切寬度 |
cropImageHeight | int | 剪切高度 |
parentFolderName | string | |
size | int | 文件大小 |
cropOffsetX | int | 圖片X軸偏移量 |
cropOffsetY | int | 圖片Y軸偏移量 |
galleryEnabledMask | boolean | |
editorImage | boolean | 是否編輯 |
cameraSource | boolean | 是否原圖 |
position | int | 位置 |
dateAddedTime | date | 文件添加時間 |
三.注意事項
從應用市場下載插件導入自己項目后,要先制作自定義插件后,才可以運行使用插件需在 Android 5.0 版本及以上方可正常使用盡量使用 HBuilderX 4.0+ 以上的最新版本,以便更好在uni-app和uni-app x中使用uts插件
2.完整代碼示例
<template><view><button @click="openPicture()">打開相冊</button><uni-grid :column="4" :highlight="true"><uni-grid-item v-for="(result, index) in resultList" :index="index" :key="index"><view style="background-color: #fff; display: flex; justify-content: center; align-items: center;"><image :src="result.path" mode="aspectFit" :style="{'width': imageSize + 'px', 'height': imageSize + 'px'}"></image></view></uni-grid-item></uni-grid><view style="margin: 10px;"> 返回值:</view><scroll-view scroll-x="true" style="margin:20px; 0px "><y-json-view :json="resultList" closed /></scroll-view></view>
</template><script>import {open} from '@/uni_modules/pic-selector'const modal = uni.requireNativePlugin('modal');export default {data() {return {imageSize:uni.getSystemInfoSync().windowWidth/4-10,resultList:[// {// "compressed": true,//是否壓縮// "compressPath": "",//壓縮路徑;設置了isCompress;時返回;// "fileName": "",//文件名// "maxSelectEnabledMask": false,// "num": 1,//文件數量// "bucketId": -643270046,// "mimeType": "image/jpeg",//文件類型// "duration": 0,//文件時長// "cropResultAspectRatio": 1,// "path": "",//原圖path,但在Android Q版本上返回的是content:// Uri類型// "checked": false,// "realPath": "",//絕對路徑// "id": 13043,// "toSandboxPath": true,//是否使用自定義輸出路徑// "sandboxPath": "",//自定義輸出路徑// "chooseModel": 0,// "width": 1134,//寬度// "height": 1780,//高度// "original": false,//是否開啟原圖// "availablePath": "",// "cut": true,//是否剪切// "cutPath": "",//裁剪后path,設置了isCrop返回// "cropImageWidth": 567,//剪切寬度// "cropImageHeight": 567,//剪切高度// "parentFolderName": "WeiXin",// "size": 392774,//文件大小// "cropOffsetX": 0,//圖片X軸偏移量// "cropOffsetY": 162,//圖片Y軸偏移量// "galleryEnabledMask": false,// "editorImage": false,// "cameraSource": false,// "position": 1,// "dateAddedTime": 1749993134// }]}},methods: {openPicture(){let _this = thislet params = {selectMimeType:0,//全部0 圖片1 視頻1 硬盤3language:0, //system Language -1; 簡體中文 0; 繁體 1; 英語 2; 韓語 3; 德語 4; 法語 5; 日語 6; 越語 7; 西班牙語 8; 葡萄牙語 9; 阿拉伯語 10; 俄語 11; 捷克 12; 哈薩克斯坦 13;isCompress:true,//是否壓縮isCrop:false,//是否剪切isCameraIntercept :true,//是否攔截相機按鈕isCameraForegroundService:true,//是否在前臺運行isDisplayCamera:true,//是否顯示相機isPageStrategy:true,//是否開啟分頁策略maxSelectNum:99,//最大選擇數量minSelectNum:0,//最小選擇數量isVideoPauseResumePlay:true,//視頻支持暫停與播放isQuickCapture:true,//使用系統攝像機錄制后,是否支持使用系統播放器立即播放視頻isPreviewAudio:true,//是否支持音頻預覽isPreviewImage:true,//是否支持預覽圖片isPreviewVideo:true,//是否支持預覽視頻isPreviewFullScreenMode:true,//是否支持全屏預覽isEmptyResultReturn:true,//是否支持未選擇返回isWithSelectVideoImage:true,//是否支持視頻圖片同選isSelectZoomAnim:true, //選擇縮略圖縮放效果isOpenClickSound:true,//是否開啟點擊音效isCameraAroundState:true,//是否開啟相機前后切換isCameraRotateImage:true,//拍照是否糾正旋轉圖片isGif:true,//是否顯示gif文件isWebp:true, //是否顯示webp文件isBmp:true,//是否顯示bmp文件isMaxSelectEnabledMask:true,//達到最大選擇數是否開啟禁選蒙層isSyncCover:true, //isPageModel模式下是否強制同步封面,默認falseisAutomaticTitleRecyclerTop:true,//點擊相冊標題是否快速回到第一項isAutoVideoPlay:true,//預覽視頻是否自動播放isLoopAutoVideoPlay:true,//預覽視頻是否循環播放isFilterSizeDuration:true,//是否過濾圖片或音視頻大小時長為0的資源isFastSlidingSelect:true,//是否快速滑動選擇isDirectReturnSingle:true,//是否直接返回單選isPageSyncAlbumCount:true,//分頁模式下設置過濾條件后是否同步專輯下資源的數量isUseSystemVideoPlayer:true,//是否使用系統自帶的視頻播放器}open(params,{onResult(result){if(result){_this.resultList = JSON.parse(result)console.log('onResult--->>',result)modal.toast({ message: _this.resultList, duration: 1.5 });}},onCancel(){console.log('onCancel--->>',result)}})}}}
</script><style>
</style>
長期維護,持續更新,對付費用戶提供終身免費技術支持