正文
;
int
y
=
(
source
.
getHeight
()
-
size
)
/
2
;
// TODO this could be acquired from the pool too
Bitmap
squared
=
Bitmap
.
createBitmap
(
source
,
x
,
y
,
size
,
size
);
Bitmap
result
=
pool
.
get
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
);
if
(
result
==
null
)
{
result
=
Bitmap
.
createBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
);
}
Canvas
canvas
=
new
Canvas
(
result
);
Paint
paint
=
new
Paint
(
Paint
.
FILTER_BITMAP_FLAG
|
Paint
.
DITHER_FLAG
|
Paint
.
ANTI_ALIAS_FLAG
);
paint
.
setShader
(
new
BitmapShader
(
squared
,
BitmapShader
.
TileMode
.
CLAMP
,
BitmapShader
.
TileMode
.
CLAMP
));
float
r
=
size
/
2f
;
canvas
.
drawCircle
(
r
,
r
,
r
,
paint
);
return
result
;
}
@Override
protected
Bitmap transform
(
BitmapPool
pool
,
Bitmap
toTransform
,
int
outWidth
,
int
outHeight
)
{
return
circleCrop
(
pool
,
toTransform
);
}
@Override
public
String
getId
()
{
return
getClass
().
getName
();
}
}
stackoverflow
http://stackoverflow.com/questions/25278821/how-do-rounded-image-with-glide-library/25806229#25806229
如果需要圆角矩形的话:
public
class
RoundTransform
extends
BitmapTransformation
{
private
int
cornerRadius
;