비트 맵을 원 모양으로 그리는 효과를 생성해야하는데이 원은 최대 반지름에 도달 할 때까지 가운데에서 자랄 것이므로 다음 방법을 작성했습니다.동일한 비트 맵을 여러 번 그리기
public Bitmap applyDrawingEffect(Bitmap src, int nRadiusprct)
{
// image size
int width = src.getWidth();
int height = src.getHeight();
// create bitmap output
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// set canvas for painting
Canvas canvas = new Canvas(result);
canvas.drawARGB(0, 0, 0, 0);
// config paint
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
// config rectangle for embedding
final Rect rect = new Rect(0, 0, width, height);
final RectF rectF = new RectF(rect);
// draw rect to canvas
//canvas.drawRoundRect(rectF, round, round, paint);
float fRadius = (width<=height) ? (width/2) : (height/2);
canvas.drawCircle(width/2, height/2, (fRadius * nRadiusprct/100), paint);
// create Xfer mode
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
// draw source image to canvas
canvas.drawBitmap(src, rect, rect, paint);
// return final image
return result;
}
반경 비율을 매개 변수로 전달한 것과 같이 제 질문은 점점 더 코드를 최적화 할 수있는 방법입니다. 매번 비트 맵을 만들어 새 캔버스 인스턴스에 할당하고 다시 칠할 필요가있는 이유는 무엇입니까? 다시 ....
동일한 비트 맵을 만들어 여러 번 그려 보면 동일한 효과를 낼 수 있습니까?
내 생각을 참조하십시오. 전체 반경에 도달 할 때까지 뷰를 무효화합니다. – wrecker
BitmapShader를 살펴보면 Paint 객체를 만들고 비트 맵의 BitmapShader를 비트 맵 셰이더에 적용한 다음 채워진 원을 그리면 필요한 작업을 수행 할 수 있습니다. BitmapShader에 대한 자습서가 있습니다. http://www.41post.com/4794/programming/android-rendering-a-path-with-a-bitmap-fill –