캔버스 그리기 작업을 원호 모양의 쐐기로 자릅니다. 그러나 클리핑 패스를 캔버스에 설정 한 후 의도 한 결과를 얻지 못하고 있습니다.Canvas.clipPath (Path)가 예상대로 잘리지 않습니다.
그림를 들어, 여기에 내가 뭘하는지입니다 :
path.reset();
//Move to point #1
path.moveTo(rect.centerX(), rect.centerY());
//Per the documentation, this will draw a connecting line from the current
//position to the starting position of the arc (at 0 degrees), add the arc
//and my current position now lies at #2.
path.arcTo(rect, 0, -30);
//This should then close the path, finishing back at the center point (#3)
path.close();
이 작동하고, 나는 단순히이 경로 (canvas.drawPath(path, paint)
)을 그릴 때 위 그림과 같이이 쐐기를 그립니다. 나는 캔버스의 클리핑 경로로이 경로를 설정하고 그러나 그것으로 그릴 :
//I've tried it with and without the Region.Op parameter
canvas.clipPath(path, Region.Op.REPLACE);
canvas.drawColor(Color.BLUE);
나는 다음과 같은 결과가 대신 (쐐기가 참조를 보여 그냥 남아) 취득을 :
그래서 대신 Path
이 아닌 Path
의 경계 사각형으로 잘리는 것처럼 보입니다. 여기 무슨 일이 일어나고 있는지 아십니까?
수정 업데이트와 마찬가지로, 하드웨어 가속을 허용하는 훨씬 더 효율적인 방법을 발견했습니다. 먼저, 클리핑 할 전체 이미지를 오프 스크린 비트 맵에 그립니다.
drawMyBitmap(bitmap);
Shader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setShader(shader);
@Override
public void onDraw(Canvas canvas) {
canvas.drawArc(rect, //The rectangle bounding the circle
startAngle, //The angle (CW from 3 o'clock) to start
sweepAngle, //The angle (CW from 3 o'clock) of the arc
true, //Boolean of whether to draw a filled arc (wedge)
paint //The paint with the shader attached
);
}
를 사용하는
는
Paint
A가 생성 HC 이상 또는 하드웨어 가속을 사용하고 있습니까? http://developer.android.com/guide/topics/graphics/hardware-accel.html 그렇다면 clipPath는 지원되지 않으며 문제가 있습니다. – Simon@ 시몬 : 세상에. ㅎ. 슬프게도 나는이 문서를 이번 주에 많이 언급했지만, 나는 그것을 간과했다. HW Accel을 비활성화하면 완벽하게 작동했습니다! 이 질문을 답으로 올리면 받아 들일 것입니다. 너는 생명의 은인이야! – kcoppock
도움이 된 것을 기쁘게 생각합니다. 행운을 빕니다. – Simon