Programming/Android
touch move 좌표를 이용할때 끊김 없이 그림 그리기
커널제로
2013. 4. 5. 11:28
안드로이드 device에서 터치입력을 받아서
드래그 시에 해당 좌표에 그림을 그리게 하면 그림이 완전 잘 그려질것 같은데
누구보다 빠르게 남들과는 다르게 선을 그으면
선이 불규칙하게 그려짐
기존의 코드.
// canvasForMask0.drawCircle(x, y, radius, paintPen);
해당 좌표에 동그라미를 그리라는 건데 이런식으로 그리면 위에 설명한대로 된다.
따라서, 이 방법을 해결하기 위해
drawLine()를 이용하여 그림을 그림
public void drawLine (float startX, float startY, float stopX, float stopY, Paint paint)
Added in API level 1
Draw a line segment with the specified start and stop x,y coordinates, using the specified paint. NOTE: since a line is always "framed", the Style is ignored in the paint.
Parameters
startX | The x-coordinate of the start point of the line |
---|---|
startY | The y-coordinate of the start point of the line |
paint | The paint used to draw the line |
시작점에서 끝점으로 paint 모양대로 쭉 그어주는 것.
슬슬 감이 오나?
////////////////////////////////////////////////////////////////////////////
arVertex.add(new Vertex(x,y, true));
for(int i=0; i<arVertex.size(); i++)
{
if(i==0) //0번째는 선을 그을때 시작되는 점이므로 loop 를 건너뛴다.
{ continue; }
if(i ==50) // arVertex가 너무 커지는 경우 프로그램에 딜레이가 생기므로 초기화를 시켜준다.
{
arVertex.clear();
break;
}
canvasForMask0.drawLine(
arVertex.get(i-1).x ,
arVertex.get(i-1).y ,
arVertex.get(i).x ,
arVertex.get(i).y ,
paintPen
);
}
////////////////////////////////////////////////////////////////////////////
arraylist를 에 드래그시에 좌표를 adding 후
루프로 돌려서 라인으로 그려주면 깔끔하게 그려진다.
arraylist의 크기가 너무 커지는 것을 방지하기 위해 50번째에 클리어를 시켜줬다.
해보니까 너무 길어지면 버버버벅~