一款针对Android平台下的图片选择器,支持从相册获取图片、视频、音频&拍照,支持裁剪(单图or多图裁剪)、压缩、主题自定义配置等功能,支持动态获取权限&适配Android 5.0+系统的开源图片选择框架。
-用前需知
-集成使用
-如何提Issues?
-功能特点
-PictureSelector路径说明
-更新日志
-主题配置-Xml方式
-主题配置-Code方式
-演示效果
-Api说明
-启动相册
-单独拍照
-自定义相机
-结果回调
-常见错误
-缓存清除
-混淆配置
-License
-兼容性测试
-联系方式
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'io.github.lucksiege:pictureselector:v2.7.3-rc08'
}
Or Maven:
<dependency>
<groupId>io.github.lucksiege</groupId>
<artifactId>pictureselector</artifactId>
<version>v2.7.3-rc08</version>
</dependency>
快捷调用,更多功能 请查看
1、onActivityResult
PictureSelector.create(this)
.openGallery(PictureMimeType.ofImage())
.imageEngine(GlideEngine.createGlideEngine()) // 请参考Demo GlideEngine.java
.forResult(PictureConfig.CHOOSE_REQUEST);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PictureConfig.CHOOSE_REQUEST:
// 结果回调
List<LocalMedia> result = PictureSelector.obtainMultipleResult(data);
break;
default:
break;
}
}
2、Callback
PictureSelector.create(this)
.openGallery(PictureMimeType.ofAll())
.imageEngine(GlideEngine.createGlideEngine())
.forResult(new OnResultCallbackListener<LocalMedia>() {
@Override
public void onResult(List<LocalMedia> result) {
// 结果回调
}
@Override
public void onCancel() {
// 取消
}
});
快捷调用,单独启动拍照或视频 根据PictureMimeType自动识别 更多功能 请查看
onActivityResult
PictureSelector.create(this)
.openCamera(PictureMimeType.ofImage())
.imageEngine(GlideEngine.createGlideEngine()) // 请参考Demo GlideEngine.java
.forResult(PictureConfig.REQUEST_CAMERA);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PictureConfig.REQUEST_CAMERA:
// 结果回调
List<LocalMedia> result = PictureSelector.obtainMultipleResult(data);
break;
default:
break;
}
}
Callback
PictureSelector.create(this)
.openCamera(PictureMimeType.ofImage())
.imageEngine(GlideEngine.createGlideEngine())
.forResult(new OnResultCallbackListener<LocalMedia>() {
@Override
public void onResult(List<LocalMedia> result) {
// 结果回调
}
@Override
public void onCancel() {
// 取消
}
});
如果需要使用自定义相机需要设置
.isUseCustomCamera(true);
Application下实现如下接口
public class App extends Application implements CameraXConfig.Provider {
private static final String TAG = App.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
}
@NonNull
@Override
public CameraXConfig getCameraXConfig() {
return Camera2Config.defaultConfig();
}
}
//包括裁剪和压缩后的缓存,要在上传成功后调用,type 指的是图片or视频缓存取决于你设置的ofImage或ofVideo 注意:需要系统sd卡权限
PictureCacheManager.deleteCacheDirFile(this,type);
// 清除所有缓存 例如:压缩、裁剪、视频、音频所生成的临时文件
PictureCacheManager.deleteAllCacheDirFile(this);
// 清除缓存且刷新图库
PictureCacheManager.deleteAllCacheDirRefreshFile(this);
// 清除缓存且刷新图库
PictureCacheManager.deleteAllCacheDirFile(this, new OnCallbackListener<String>() {
@Override
public void onCall(String absolutePath) {
// 清空缓存并刷新相册
}
});
// 预览图片 可自定长按保存路径
*注意 .themeStyle(R.style.theme);里面的参数不可删,否则闪退...
PictureSelector.create(this)
.themeStyle(R.style.picture_default_style)
.isNotPreviewDownload(true)
.imageEngine(GlideEngine.createGlideEngine()) // 请参考Demo GlideEngine.java
.openExternalPreview(position, result);
PictureSelector.create(this).externalPictureVideo(video_path);
- PhotoView
- luban
- ucrop
#PictureSelector 2.0
-keep class com.luck.picture.lib.** { *; }
#Ucrop
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
Copyright 2017 Luck
Licensed 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 at
http://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.
Android开发交流 新群 662320389
Android开发交流 群一 619458861 (已满)
Android开发交流 群二 679824206 (已满)
Android开发交流 群三 854136996 (已满)
QQ 893855882
腾讯优测-深度测试-通过率达到100%
单一模式 | 混选模式 |
---|---|
默认风格 | 预览 | 多图裁剪 |
---|---|---|
数字风格 | 预览 | 多图裁剪 |
---|---|---|
白色风格 | 预览 | 单图裁剪 |
---|---|---|
全新风格 | 预览 | 多图裁剪 |
---|---|---|
相册目录 | 单选模式 | 头像裁剪 |
---|---|---|
白色风格 | 视频 | 音频 |
---|---|---|