PictureSelector 2.0
https://github.com/LuckSiege/PictureSelector
一款针对Android平台下的图片选择器,支持从相册获取图片、视频、音频&拍照,支持裁剪(单图or多图裁剪)、压缩、主题自定义配置等功能,支持动态获取权限&适配Android 5.0+系统的开源图片选择框架。
预览图
最新版本
implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.5.8'
启动相册
快捷调用,更多功能 请查看
1、onActivityResult
PictureSelector.create(this)
.openGallery(PictureMimeType.ofImage())
.loadImageEngine(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> selectList = PictureSelector.obtainMultipleResult(data);
break;
default:
break;
}
}
2、Callback
PictureSelector.create(this)
.openGallery(PictureMimeType.ofAll())
.loadImageEngine(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())
.loadImageEngine(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> selectList = PictureSelector.obtainMultipleResult(data);
break;
default:
break;
}
}
Callback
PictureSelector.create(this)
.openCamera(PictureMimeType.ofImage())
.loadImageEngine(GlideEngine.createGlideEngine())
.forResult(new OnResultCallbackListener<LocalMedia>() {
@Override
public void onResult(List<LocalMedia> result) {
// 结果回调
}
@Override
public void onCancel() {
// 取消
}
});