0
如何在不裁剪圖像的情況下進行圓變換?我一直在嘗試2天,並且一直在失敗。這是我迄今爲止最接近的,但正如你所看到的,圖像不在圓圈內部居中。沒有裁剪的畢加索圓變換圖片
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
Bitmap squaredBitmap = Bitmap.createScaledBitmap(source,size-50, size-50,true);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size
, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size/2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
這是結果: