Search in sources :

Example 1 with CropCircleTransformation

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);
}
Also used : BlurTransformation(jp.wasabeef.glide.transformations.BlurTransformation) RequestOptions(com.bumptech.glide.request.RequestOptions) CropCircleTransformation(jp.wasabeef.glide.transformations.CropCircleTransformation) GrayscaleTransformation(jp.wasabeef.glide.transformations.GrayscaleTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) MultiTransformation(com.bumptech.glide.load.MultiTransformation) RoundedCornersTransformation(jp.wasabeef.glide.transformations.RoundedCornersTransformation)

Example 2 with CropCircleTransformation

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();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) BmobException(cn.bmob.v3.exception.BmobException) FileOutputStream(java.io.FileOutputStream) UploadFileListener(cn.bmob.v3.listener.UploadFileListener) CropCircleTransformation(jp.wasabeef.glide.transformations.CropCircleTransformation) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) BmobFile(cn.bmob.v3.datatype.BmobFile)

Aggregations

CropCircleTransformation (jp.wasabeef.glide.transformations.CropCircleTransformation)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 BmobFile (cn.bmob.v3.datatype.BmobFile)1 BmobException (cn.bmob.v3.exception.BmobException)1 UploadFileListener (cn.bmob.v3.listener.UploadFileListener)1 MultiTransformation (com.bumptech.glide.load.MultiTransformation)1 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 BlurTransformation (jp.wasabeef.glide.transformations.BlurTransformation)1 GrayscaleTransformation (jp.wasabeef.glide.transformations.GrayscaleTransformation)1 RoundedCornersTransformation (jp.wasabeef.glide.transformations.RoundedCornersTransformation)1