參考項目地址 https://blog.csdn.net/iamchan/article/details/81261524
https://github.com/bumptech/glide 此項目中glide使用 3.7.0 高版本的報錯 為啥`````俺也不知
github地址 https://github.com/crazycodeboy/TakePhoto
在按鈕里面直接調用onClickTake(getTakePhoto);即可
public void onClickTake(TakePhoto takePhoto) {
configCompress(takePhoto);
takePhoto.onPickMultiple(1);//根據需求這里面放最大圖片數 單選使用takePhoto.onPickFromGallery();
}
private void configCompress(TakePhoto takePhoto) {//壓縮的配置
int maxSize = Integer.parseInt("409600");//最大 壓縮
int width = Integer.parseInt("800");//寬
int height = Integer.parseInt("800");//高
CompressConfig config;
config = new CompressConfig.Builder().setMaxSize(maxSize)
.setMaxPixel(width >= height ? width : height)
.enableReserveRaw(false)//拍照壓縮后是否顯示原圖
.create();
takePhoto.onEnableCompress(config, false);//是否顯示進度條
}
需要實現繼承 TakePhotoActivity 或者 TakePhotoFragment
實現 takeSuccess() takeFail() takeCancel()
takeSuccess 方法中可以取到返回值的圖片 像這樣
public void takeSuccess(TResult result) {
super.takeSuccess(result);
Glide.with(getApplicationContext()).load(result.getImages().get(0).getCompressPath()).into(ivTest);
}