Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/starforluck/pictureselector
Picture Selector Library for Android
https://github.com/starforluck/pictureselector
android android-image-selector camera compress glide image-compression image-picker images luban multi-select photo photoview pictureselector video
Last synced: 3 months ago
JSON representation
Picture Selector Library for Android
- Host: GitHub
- URL: https://github.com/starforluck/pictureselector
- Owner: StarForLuck
- License: apache-2.0
- Created: 2024-05-21T03:02:05.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-05-24T06:32:01.000Z (7 months ago)
- Last Synced: 2024-10-15T16:02:47.115Z (3 months ago)
- Topics: android, android-image-selector, camera, compress, glide, image-compression, image-picker, images, luban, multi-select, photo, photoview, pictureselector, video
- Language: Java
- Homepage:
- Size: 44.2 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PictureSelector 3.0
A PictureSelector for Android platform, which supports obtaining pictures, videos, audio & photos from photo albums, cutting (single picture or multi picture cutting), compression, theme custom configuration and other functions, and supports dynamic access & an open source picture selection framework suitable for Android 5.0 + system
[简体中文🇨🇳](README_CN.md)[Download Demo Apk](https://github.com/StarForLuck/PictureSelector/raw/master/app/demo/demo_2024-05-21_025734_v3.11.3.apk)
[![Maven Central](https://img.shields.io/badge/maven%20central-v3.11.3-yellow)](https://github.com/LuckSiege)
[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/LuckSiege)
[![Star](https://img.shields.io/github/stars/LuckSiege/PictureSelector.svg)](https://github.com/StarForLuck/PictureSelector)## Contents
-[Latest version](https://github.com/StarForLuck/PictureSelector/releases/tag/v3.11.3)
-[Download](#Download)
-[Usage](#Usage)
-[Permission](#Permission)
-[Result description](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-LocalMedia%E8%AF%B4%E6%98%8E)
-[Effect](#Effect)
-[ProGuard](#ProGuard)
-[Common errors](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%B8%B8%E8%A7%81%E9%94%99%E8%AF%AF)
-[Issues](https://github.com/StarForLuck/PictureSelector/wiki/%E5%A6%82%E4%BD%95%E6%8F%90Issues%3F)
-[License](#License)## Download
Use Gradle
```sh
repositories {
google()
mavenCentral()
}dependencies {
// PictureSelector basic (Necessary)
implementation 'io.github.lucksiege:pictureselector:v3.11.3'// image compress library (Not necessary)
implementation 'io.github.lucksiege:compress:v3.11.3'// uCrop library (Not necessary)
implementation 'io.github.lucksiege:ucrop:v3.11.3'// simple camerax library (Not necessary)
implementation 'io.github.lucksiege:camerax:v3.11.3'
}
```Kotlin Version [Demo](https://github.com/StarForLuck/PictureSelector/tree/kotlin)
```sh
dependencies {
// Please do not upgrade across versions, please check the Kotlin version demo first
implementation 'io.github.lucksiege:pictureselector:kotlin-v1.0.0-beta'
}
```Or Maven:
```sh
io.github.lucksiege
pictureselector
v3.11.3io.github.lucksiege
compress
v3.11.3io.github.lucksiege
ucrop
v3.11.3io.github.lucksiege
camerax
v3.11.3```
## Permission
Permission describe,see [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector%E6%9D%83%E9%99%90%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E)
```sh
Android 13版本适配,细化存储权限
```
Android 11 use camera,AndroidManifest.xm add the code:
```sh
```
## ImageEngine
[GlideEngine](https://github.com/StarForLuck/PictureSelector/blob/master/app/src/main/java/com/luck/pictureselector/GlideEngine.java)
[PicassoEngine](https://github.com/StarForLuck/PictureSelector/blob/master/app/src/main/java/com/luck/pictureselector/PicassoEngine.java)
[CoilEngine](https://github.com/StarForLuck/PictureSelector/blob/master/app/src/main/java/com/luck/pictureselector/CoilEngine.java)## Usage
For more features, see [documentation](https://github.com/StarForLuck/PictureSelector/wiki/Api%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3)A simple use case is shown below:
1、Get picture
```sh
PictureSelector.create(this)
.openGallery(SelectMimeType.ofImage())
.setImageEngine(GlideEngine.createGlideEngine())
.forResult(new OnResultCallbackListener() {
@Override
public void onResult(ArrayList result) {}
@Override
public void onCancel() {}
});
```Using system albums
```sh
PictureSelector.create(this)
.openSystemGallery(SelectMimeType.ofImage())
.forResult(new OnResultCallbackListener() {
@Override
public void onResult(ArrayList result) {}
@Override
public void onCancel() {}
});
```2、Only use camera
```sh
PictureSelector.create(this)
.openCamera(SelectMimeType.ofImage())
.forResult(new OnResultCallbackListener() {
@Override
public void onResult(ArrayList result) {}
@Override
public void onCancel() {}
});
```To take photos separately in the Navigation Fragment scene, please use the following methods:
```sh
PictureSelector.create(this)
.openCamera(SelectMimeType.ofImage())
.forResultActivity(new OnResultCallbackListener() {
@Override
public void onResult(ArrayList result) {}
@Override
public void onCancel() {}
});
```3、You can also use the following example:
(1)、Inject into any view fragment
```sh
PictureSelector.create(this)
.openGallery(SelectMimeType.ofAll())
.setImageEngine(GlideEngine.createGlideEngine())
.buildLaunch(R.id.fragment_container, new OnResultCallbackListener() {
@Override
public void onResult(ArrayList result) {
}@Override
public void onCancel() {
}
});
```(2)、Custom Inject into any view fragment
```sh
PictureSelectorFragment selectorFragment = PictureSelector.create(this)
.openGallery(SelectMimeType.ofAll())
.setImageEngine(GlideEngine.createGlideEngine())
.build();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, selectorFragment, selectorFragment.getFragmentTag())
.addToBackStack(selectorFragment.getFragmentTag())
.commitAllowingStateLoss();
```4、Only query data source
(1)、get album data
```sh
PictureSelector.create(this)
.dataSource(SelectMimeType.ofAll())
.obtainAlbumData(new OnQueryDataSourceListener() {
@Override
public void onComplete(List result) {}
);```
(2)、get media data
```sh
PictureSelector.create(this)
.dataSource(SelectMimeType.ofAll())
.obtainMediaData(new OnQueryDataSourceListener() {
@Override
public void onComplete(List result) {}
);```
(3)、IBridgeMediaLoader get data
```sh
IBridgeMediaLoader loader = PictureSelector.create(this)
.dataSource(SelectMimeType.ofImage()).buildMediaLoader();
loader.loadAllAlbum(new OnQueryAllAlbumListener() {
@Override
public void onComplete(List result) {}
});```
5、Preview image、video、audio
If you preview the online video AndroidManifest XML add the following code
```sh
android:usesCleartextTraffic="true"
``````sh
PictureSelector.create(this)
.openPreview()
.setImageEngine(GlideEngine.createGlideEngine())
.setExternalPreviewEventListener(new OnExternalPreviewEventListener() {
@Override
public void onPreviewDelete(int position) {}
@Override
public boolean onLongPressDownload(LocalMedia media) {
return false;
}
}).startActivityPreview(position, true, "data");```
Set theme,see [documentation](https://github.com/StarForLuck/PictureSelector/wiki/Api-UI%E8%AF%B4%E6%98%8E)
```sh
.setSelectorUIStyle();
```
Or Overload layout,see [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E9%87%8D%E8%BD%BD%E5%B8%83%E5%B1%80%EF%BC%9F)```sh
.setInjectLayoutResourceListener(new OnInjectLayoutResourceListener() {
@Override
public int getLayoutResourceId(Context context, int resourceSource) {
return 0;
}
```The advanced use cases are as follow:
1、Use the custom camera,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9B%B8%E6%9C%BA%EF%BC%9F)
```sh
.setCameraInterceptListener(new OnCameraInterceptListener() {
@Override
public void openCamera(Fragment fragment, int cameraMode, int requestCode){}
});
```2、Use the image compress,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E5%8E%8B%E7%BC%A9%EF%BC%9F)
```sh
.setCompressEngine(new CompressFileEngine() {
@Override
public void onStartCompress(Context context, ArrayList source, OnKeyValueResultCallbackListener call){}
});
```3、Use the image uCrop,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E8%A3%81%E5%89%AA%EF%BC%9F)
```sh
.setCropEngine(new CropFileEngine() {
@Override
public void onStartCrop(Fragment fragment, Uri srcUri, Uri destinationUri, ArrayList dataSource, int requestCode) {}
});
```4、Use the image edit,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E7%BC%96%E8%BE%91%E5%9B%BE%E7%89%87%EF%BC%9F)
```sh
.setEditMediaInterceptListener(new OnMediaEditInterceptListener() {
@Override
public void onStartMediaEdit(Fragment fragment, LocalMedia currentLocalMedia, int requestCode) {}
});```
5、Use the custom load data,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E5%8A%A0%E8%BD%BD%E8%87%AA%E5%AE%9A%E4%B9%89%E6%95%B0%E6%8D%AE%E6%BA%90%EF%BC%9F)
```sh
.setExtendLoaderEngine(new ExtendLoaderEngine() {
@Override
public void loadAllAlbumData(Context context, OnQueryAllAlbumListener query) {
}@Override
public void loadOnlyInAppDirAllMediaData(Context context, OnQueryAlbumListener query) {}
@Override
public void loadFirstPageMediaData(Context context, long bucketId, int page, int pageSize, OnQueryDataResultListener query) {}
@Override
public void loadMoreMediaData(Context context, long bucketId, int page, int limit, int pageSize, OnQueryDataResultListener query) {}
});```
6、Use the custom apply Permissions,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9D%83%E9%99%90%E7%94%B3%E8%AF%B7-%EF%BC%9F)
```sh
.setPermissionsInterceptListener(new OnPermissionsInterceptListener() {
@Override
public void requestPermission(Fragment fragment, String[] permissionArray, OnRequestPermissionListener call) {}
@Override
public boolean hasPermissions(Fragment fragment, String[] permissionArray) {
return false;
}
});```
7、Android 10 and above, Sandbox mechanism, file processing,Permissions,See [documentation](https://github.com/StarForLuck/PictureSelector/wiki/PictureSelector-3.0-%E5%A6%82%E4%BD%95%E8%AE%BF%E9%97%AE%E6%B2%99%E7%9B%92%E5%A4%96%E8%B5%84%E6%BA%90%EF%BC%9F)
```sh
.setSandboxFileEngine(new UriToFileTransformEngine() {
@Override
public void onUriToFileAsyncTransform(Context context, String srcPath, String mineType, OnKeyValueResultCallbackListener call) {
}
});
```## ProGuard
```sh
-keep class com.luck.picture.lib.** { *; }// use Camerax
-keep class com.luck.lib.camerax.** { *; }// use uCrop
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
```
## License
```sh
Copyright 2016 LuckLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```## Effect
| Function list |
|:-----------:|
|![](image/home.jpg)|| Default Style | Preview | Multiple Crop |
|:-----------:|:--------:|:---------:|
|![](image/picture_default_style_1.jpg) | | ![](image/picture_default_style_new_3.jpg)|| Digital Style | Preview | Multiple Crop |
|:-----------:|:--------:|:---------:|
|![](image/picture_num_style_new_1.jpg) | ![](image/picture_num_style_new_2.jpg) | ![](image/picture_num_style_new_3.jpg)|| White Style | Preview | Single Crop |
|:-----------:|:--------:|:---------:|
|![](image/picture_sina_style_1.jpg) | ![](image/picture_sina_style_new_2.jpg) | ![](image/picture_sina_style_new_3.jpg)|| New Style | Preview | Multiple Crop |
|:-----------:|:--------:|:---------:|
|![](image/picture_wechat_style_1.jpg) | ![](image/picture_wechat_style_2.jpg) | ![](image/picture_wechat_style_new_3.jpg)|| Photo Album Directory | Single Mode | Circular Crop|
|:-----------:|:--------:|:--------:|
|![](image/picture_wechat_album_style.jpg) |![](image/picture_wechat_single_style_3.jpg) | ![](image/picture_circular_crop_new_style.jpg)|| White Style | Video | Audio |
|:-----------:|:-----------:|:--------:|
|![](image/picture_white_style.jpeg) |![](image/picture_video.jpg) | ![](image/picture_audio.jpg)|