안녕하세요~
몇시간째 고민하다가 도저히 저의 머리로는 해결이 되지 않아 질문 드립니다!!
mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap을 생성할때 사각형이 아닌 원형으로 생성하는 방법이 있을까요??
또, bitmap을 생성할때 시작점(x,y)를 지정할 수 있는지요..ㅠㅠ
방법은 있을 것 같은데..자료를 못찾겠네요..
혹시 아시는 분이 있으시면 답변 좀 부탁 드립니다..ㅠㅠ
bitmap 생성을 원형으로 한다기보다 원형으로 clip되어 있는 canvas에 bitmap을 새로 그리는 방법입니다.
apidemo의 clipping을 응용한 예입니다.
아래 소스에서 canvas.translate(0, 0); 의 좌표를 조정하면 bitmap이 그려지는 시작점을 변경할 수 있습니다.
====================================================================
public Bitmap roundBitmap(Bitmap source) {
int w = source.getWidth();
int h = source.getHeight();
Bitmap rounder = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(rounder);
Path mPath = new Path();
BitmapDrawable drawable = new BitmapDrawable(source);
drawable.setBounds(0, 0, w, h);
canvas.translate(0, 0);
mPath.reset();
canvas.clipPath(mPath);
mPath.addCircle(w/2, h/2, w/2, Path.Direction.CCW);
canvas.clipPath(mPath, Region.Op.REPLACE);
drawable.draw(canvas);
return rounder;
}
====================================================================