use of jp.wasabeef.glide.transformations.CropCircleTransformation in project DevRing by LJYcoder.
the class GlideManager method load.
private RequestBuilder load(RequestBuilder requestBuilder, LoadOption loadOption) {
RequestOptions requestOptions = new RequestOptions();
// 使用全局的配置进行设置
if (loadOption == null) {
if (mImageConfig.isShowTransition()) {
requestBuilder.transition(DrawableTransitionOptions.withCrossFade(600));
}
if (mImageConfig.getLoadingResId() > 0) {
requestOptions.placeholder(mImageConfig.getLoadingResId());
}
if (mImageConfig.getErrorResId() > 0) {
requestOptions.error(mImageConfig.getErrorResId());
}
} else // 使用临时的配置进行设置
{
if (loadOption.isShowTransition()) {
requestBuilder.transition(DrawableTransitionOptions.withCrossFade(600));
}
if (loadOption.getLoadingResId() > 0) {
requestOptions.placeholder(loadOption.getLoadingResId());
}
if (loadOption.getErrorResId() > 0) {
requestOptions.error(loadOption.getErrorResId());
}
CropCircleTransformation cropCircleTransformation = null;
RoundedCornersTransformation roundedCornersTransformation = null;
BlurTransformation blurTransformation = null;
GrayscaleTransformation grayscaleTransformation = null;
if (loadOption.isCircle()) {
cropCircleTransformation = new CropCircleTransformation();
} else if (loadOption.getRoundRadius() > 0) {
roundedCornersTransformation = new RoundedCornersTransformation(loadOption.getRoundRadius(), 0);
}
if (loadOption.getBlurRadius() > 0) {
blurTransformation = new BlurTransformation(loadOption.getBlurRadius());
}
if (loadOption.isGray()) {
grayscaleTransformation = new GrayscaleTransformation();
}
MultiTransformation multiTransformation = getMultiTransformation(new CenterCrop(), cropCircleTransformation, roundedCornersTransformation, blurTransformation, grayscaleTransformation);
if (multiTransformation != null)
requestOptions.transform(multiTransformation);
}
return requestBuilder.apply(requestOptions);
}
use of jp.wasabeef.glide.transformations.CropCircleTransformation in project Palm300Heroes by nicolite.
the class UserInfoActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
PermissionUtils.getInstance().requestPermission(this, 100, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (requestCode == REQUEST_CODE_CHOOSE_PICTURE && resultCode == RESULT_OK) {
List<Uri> uriList = Matisse.obtainResult(data);
for (Uri uri : uriList) {
Intent intent = new Intent();
intent.setAction("com.android.camera.action.CROP");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// mUri是已经选择的图片Uri
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
// 裁剪框比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// 输出图片大小
intent.putExtra("outputX", 150);
intent.putExtra("outputY", 150);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_CODE_PICTURE_CUT);
}
} else if (requestCode == REQUEST_CODE_PICTURE_CUT && resultCode == RESULT_OK) {
try {
Bitmap bitmap = data.getParcelableExtra("data");
File file = new File(Environment.getExternalStorageDirectory(), "P300Heroes/");
if (!file.exists()) {
boolean mkdir = file.mkdir();
if (!mkdir) {
ToastUtils.showToastShort("创建文件失败,请检查是否给予文件读写权限!");
return;
}
}
File file2 = new File(Environment.getExternalStorageDirectory(), "P300Heroes/cache/");
if (!file2.exists()) {
boolean mkdir = file2.mkdir();
if (!mkdir) {
ToastUtils.showToastShort("创建文件失败,请检查是否给予文件读写权限!");
return;
}
}
final File file1 = new File(file, userData.getUsername() + "_" + System.currentTimeMillis() + ".jpg");
FileOutputStream fileOutputStream = new FileOutputStream(file1);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
final BmobFile bmobFile = new BmobFile(file1);
bmobFile.uploadblock(new UploadFileListener() {
@Override
public void done(BmobException e) {
if (e == null) {
user.setAvatar(bmobFile);
Glide.with(UserInfoActivity.this).load(file1).bitmapTransform(new CropCircleTransformation(UserInfoActivity.this)).centerCrop().crossFade().into(userAvatar);
saveUserInfo(user);
if (file1.exists() && file1.isFile()) {
file1.delete();
}
} else {
ToastUtils.showToastShort("图片上传失败!" + e.toString());
}
}
@Override
public void onProgress(Integer value) {
super.onProgress(value);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations