开发者

Draw a pencil stoke using DrawLines() in android

开发者 https://www.devze.com 2023-03-22 10:20 出处:网络
There is an array \'a\' which hold开发者_如何学Cs the points b/w which lines have to be drawn: float[] a = {0.0f, 1.2f, 3.4f, -9.87f, 65.4f, 0.0f, 567.9f};

There is an array 'a' which hold开发者_如何学Cs the points b/w which lines have to be drawn:

  float[] a = {0.0f, 1.2f, 3.4f, -9.87f, 65.4f, 0.0f, 567.9f};
  canvas.drawLines(a,mypaint);

Now what drawLines(float[] pts, Paint paint) does is that it draws a line b/w a[0], a[1] and a[2], a[3] and then the next line b/w a[4], a[5] and a[6], a[7].

now I want a line b/w a[2], a[3] and a[4], a[5] as well.

So how to do that? Will drawLines (float[] pts, int offset, int count, Paint paint) help?? i dont understand the offset and count parameters? I wanted to use offset = -2 as parameter so that I a[2],a[3] are read twice.


From the documentation:

public void drawLines (float[] pts, int offset, int count, Paint paint)

offset Number of values in the array to skip before drawing.

count The number of values in the array to process, after skipping "offset" of them. Since

So to draw a line just between (a[2], a[3]) and (a[4], a[5]) you would call it like this:

canvas.drawlines(a, mypaint, 2, 4);

This skips a[0],a[1], then begins taking pairs of two at a[2],a[3], and finishes at a[4],a[5] (because each line uses 4 values, x, y pairs)

I did not see anything in the documentation about using negative offsets, but you should experiment and consider reading the source to find out. I don't think they are supported, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号