2017-09-01 57 views
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; 
} 

這是結果:

enter image description here

回答

0

使用此CircleImageView

<de.hdodenhof.circleimageview.CircleImageView 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/image1" 
    android:layout_width="96dp" 
    android:layout_height="96dp" 
    android:src="@drawable/menu1" 
    app:border_width="2dp" 
    app:border_color="@color/white" 
/> 

欲瞭解更多信息:https://github.com/hdodenhof/CircleImageView