2013-04-26 5 views
0

나는 안드로이드를 배우고 캔버스에 다른 도형을 그리려하고있다. 순간 나는 다른 각도 타원형으로 붙어있다 : 나는 path.addRoundRect() 방법 (반경의 배열을 취하는 일)을 사용하려고했습니다안드로이드에서 도형을 그리는 법

enter image description here

하지만 알아낼 수있는 것을 값은 내가해야 그런 모양을 이루기 위해 그곳을 지나가십시오. 또한 path.lineTo()을 사용해 보았지만 그런 결과를 얻을 수 없었습니다 (비슷한 종류 였지만 여전히 필요한 것은 아닙니다). 이것을 달성하기위한 좋은 해결책은 무엇입니까?

편집 1 : 내가 시도하는 것은 다음입니다 :

Path path= new Path(); 
    path.moveTo(x - radius, y - radius/ 1.5f); 
    path.lineTo(x - radius/ 4, y - radius); 
    path.lineTo(x, y - radius); 
    path.lineTo(x + radius/ 2, y - radius); 
    path.lineTo(x + radius, y - radius/ 2); 
    path.lineTo(x, y + radius/ 2); 
    path.lineTo(x - radius/ 2, y + radius/ 1.5f); 
    path.lineTo(x - radius, y + radius/ 4); 
    path.lineTo(x - radius, y - radius/ 1.5f); 
    path.close(); 

Paint pathPaint = new Paint(); 
     pathPaint.setColor(Color.BLACK);      
     pathPaint.setStrokeWidth(2.5f);    
     pathPaint.setDither(true);      
     pathPaint.setStyle(Style.STROKE);  
     pathPaint.setStrokeJoin(Join.ROUND); 
     pathPaint.setStrokeCap(Cap.ROUND);  
     pathPaint.setPathEffect(new CornerPathEffect(20)); 
     pathPaint.setAntiAlias(true); 
     canvas.drawOval(new RectF(x - radius, y - radius+ 2, x + radius-2, y + radius- 2), pathPaint); 
     canvas.drawPath(path, pathPaint); 

X와 Y는 디스플레이 및 반경에 대한 몇 가지 좌표는 원의 반경 (내가 원으로 그리기 시작했다). 14px와 같습니다.

float[] radii = new float[] { 
       5, 
       5, 
       1, 
       1, 
       5, 
       1, 
       1, 
       1, 

     }; 
     path.addRoundRect(new RectF(x - radius, y - radius, x + radius, 

y + radius), 
        radii, Direction.CW); 
canvas.drawPath(path, pathPaint); 
+0

코드를 게시 할 수 있습니까? – petey

+0

http://developer.android.com/reference/android/graphics/drawable/shapes/OvalShape.html –

답변

0

가 Canvas.skew() 함수를보십시오 :

나는이 방법을 시도했습니다. 아래 URL에 좋은 예가 있습니다. 기울이기는 그려지는 점을 "기울입니다". 캔버스의 현재 중심을 기준으로 다른 결과를 얻으므로 필요에 따라 translate()를 수행하여 원하는 결과를 얻습니다.

http://css3files.com/transform/

+0

제안 해 주셔서 감사합니다. 나는이 프로젝트 atm에서 일하지 않기 때문에 그것을 검증 할 수 없다. 어쩌면 다른 사람이 작동하는지 여부를 확인할 수 있습니다. –

관련 문제