9

image \ bitmapを円にトリミングする方法を知っている人はいますか?解決策が見つかりません。申し訳ありません。

4

6 に答える 6

1

Wiseman Designs には、すぐに使用できるオープン ソースの Circular ImageView があります。

https://github.com/wisemandesigns/CircularImageView

これにより、レイアウトで XML が使用されるため、作業が楽になります。XML でソースを設定するか、ビットマップを簡単に使用できる小さな変更を加えることができます。

免責事項: 私は Wiseman Designs で働いています

于 2014-09-03T09:41:44.587 に答える
0

以下のコードで試してください:

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
  // TODO Auto-generated method stub
  int targetWidth = 50;
  int targetHeight = 50;
  Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, 
                            targetHeight,Bitmap.Config.ARGB_8888);

                Canvas canvas = new Canvas(targetBitmap);
  Path path = new Path();
  path.addCircle(((float) targetWidth - 1) / 2,
  ((float) targetHeight - 1) / 2,
  (Math.min(((float) targetWidth), 
                ((float) targetHeight)) / 2),
          Path.Direction.CCW);

                canvas.clipPath(path);
  Bitmap sourceBitmap = scaleBitmapImage;
  canvas.drawBitmap(sourceBitmap, 
                                new Rect(0, 0, sourceBitmap.getWidth(),
    sourceBitmap.getHeight()), 
                                new Rect(0, 0, targetWidth,
    targetHeight), null);
  return targetBitmap;
 }
于 2014-03-18T05:56:32.497 に答える
0
finalBitmapShader shader = newBitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mPaint.setShader(shader);
mBitmapWidth=mBitmap.getWidth();
mBitmapHeight=mBitmap.getHeight();
}
@Override
public void draw(Canvas canvas{ 
  canvas.drawOval(mRectF,mPaint);
}
@Override
protected void onBoundsChange(Rect bounds) {
  super.onBoundsChange(bounds);
  mRectF.set(bounds);
}

ここで、 http://androidgreeve.blogspot.in/2014/09/facebook-messanger-like-profile-image.html?m= 1 でサンプル チュートリアルを見つけました。

于 2014-09-03T09:33:16.347 に答える