| | |
| | | import android.graphics.Paint; |
| | | import android.graphics.RectF; |
| | | import android.support.annotation.NonNull; |
| | | import android.util.Log; |
| | | |
| | | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; |
| | | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; |
| | | import com.bumptech.glide.load.resource.bitmap.TransformationUtils; |
| | | import com.bumptech.glide.util.Util; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | |
| | | */ |
| | | public class GlideRoundTransform extends BitmapTransformation { |
| | | private static final String ID = GlideRoundTransform.class.getClass().getName(); |
| | | private static final String TAG = "GlideRoundTransform"; |
| | | private static byte[] ID_BYTES = null; |
| | | private static float radius = 0f; |
| | | private float radius = 0f; |
| | | |
| | | public GlideRoundTransform(Context context) { |
| | | this(context, 12); |
| | |
| | | @Override |
| | | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, |
| | | int outWidth, int outHeight) { |
| | | return roundCrop(pool, toTransform); |
| | | //处理centercrop |
| | | Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight); |
| | | return roundCrop(pool, bitmap == null ? toTransform : bitmap); |
| | | } |
| | | |
| | | private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { |
| | | private Bitmap roundCrop(BitmapPool pool, Bitmap source) { |
| | | if (source == null) |
| | | return null; |
| | | |
| | | Log.i(TAG, "源图片大小:" + source.getWidth() + "-" + source.getHeight()); |
| | | |
| | | Bitmap result = pool.get(source.getWidth(), source.getHeight(), |
| | | Bitmap.Config.ARGB_8888); |
| | | if (result == null) { |