Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 划线问题_Iphone - Fatal编程技术网

Iphone 划线问题

Iphone 划线问题,iphone,Iphone,我正在使用此代码在TouchsMoved中绘制 当我画得很快的时候,我确实会有空隙。。。怎么办?您应该使用UITouch的previousLocationInView:方法获取您手指所在的上一个已知点,并在该点和当前位置之间画一条线 另一种解决方案是在两次调用之间将currentPoint保持在静态变量中。CGContextBeginPath(Mycontext); brushSize=1.0f; UIGraphicsBeginImageContext(self.view.frame.size)

我正在使用此代码在TouchsMoved中绘制


当我画得很快的时候,我确实会有空隙。。。怎么办?

您应该使用UITouch的
previousLocationInView:
方法获取您手指所在的上一个已知点,并在该点和当前位置之间画一条线

另一种解决方案是在两次调用之间将currentPoint保持在静态变量中。

CGContextBeginPath(Mycontext);
brushSize=1.0f;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapButt); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brushSize);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 1.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x+brushSize*4,lastPoint.y-brushSize);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x-brushSize, lastPoint.y+brushSize*4);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGContextMoveToPoint(Mycontext,lastPoint.x,lastPoint.y); int x、cx、deltax、xstep、y、cy、deltay、ystep、error、st、dupe; int x0,y0,x1,y1; x0=当前点.x; y0=当前点y; x1=最后一点x; y1=最后一点y; //查找像素步长的最大增量 st=(abs(y1-y0)>abs(x1-x0)); //如果deltay>deltax,则交换x,y if(st){ (x0^=y0);(y0^=x0);(x0^=y0);//交换(x0,y0); (x1^=y1);(y1^=x1);(x1^=y1);//交换(x1,y1); } deltax=abs(x1-x0); deltay=abs(y1-y0); 错误=(deltax/2); y=y0; 如果(x0>x1){xstep=-1;} else{xstep=1;} 如果(y0>y1){ystep=-1;} else{ystep=1;} 对于((x=x0);(x!=(x1+xstep));(x+=xstep)) { (cx=x);(cy=y);//x的副本,y的副本 //如果x,y在上面交换,现在将它们交换回来 如果(st){(cx^=cy);(cy^=cx);(cx^=cy);} (dupe=0);//初始化无dupe 如果(!dupe){ CGContextMoveToPoint(UIGraphicsGetCurrentContext(),cx+brushSize*4,cy brushSize); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),cx brushSize,cy+brushSize*4); } (error-=deltay);//向行尾收敛 如果(错误<0){//尚未完成 (y+=ystep); (错误+=deltax); } } CGContextStrokePath(Mycontext); Image_Cookie.Image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsSendImageContext(); lastPoint=currentPoint;
@vdsmedT。。。。CGPoint currentPoint=[touch previousLocationInView:self.view];如果我在TouchsMoved中使用此选项,则它不会更改….CGPoint prevPoint=[touch previousLocationInView:self.view];CGPoint curPoint=[触摸位置视图:self.view]@vdsmedT。。。。我也使用了previouslocationInView。。。。。。。我画画的时候还是会有间隙。@kiran:那就试试另一种方法吧。将当前点保留在静态变量中,作为下一次touchesMouved调用的起点。
CGContextBeginPath(Mycontext);
CGContextMoveToPoint(Mycontext, lastPoint.x, lastPoint.y);

int x, cx, deltax, xstep,y, cy, deltay, ystep,error, st, dupe;
int x0, y0, x1, y1;

x0 = currentPoint.x;
y0 = currentPoint.y;
x1 = lastPoint.x;
y1 = lastPoint.y;

// find largest delta for pixel steps
st = (abs(y1 - y0) > abs(x1 - x0));

// if deltay > deltax then swap x,y
if (st) {
(x0 ^= y0); (y0 ^= x0); (x0 ^= y0); // swap(x0, y0);
(x1 ^= y1); (y1 ^= x1); (x1 ^= y1); // swap(x1, y1);
}

deltax = abs(x1 - x0);
deltay = abs(y1 - y0);
error = (deltax / 2);
y = y0;

if (x0 > x1) { xstep = -1; }
else { xstep = 1; }

if (y0 > y1) { ystep = -1; }
else { ystep = 1; }

for ((x = x0); (x != (x1 + xstep)); (x += xstep))
{
(cx = x); (cy = y); // copy of x, copy of y

// if x,y swapped above, swap them back now
if (st) { (cx ^= cy); (cy ^= cx); (cx ^= cy); }

(dupe = 0); // initialize no dupe

if(!dupe) {
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), cx+brushSize*4,cy-brushSize);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), cx-brushSize, cy+brushSize*4);

}

(error -= deltay); // converge toward end of line

if (error < 0) { // not done yet
(y += ystep);
(error += deltax);
}
}

CGContextStrokePath(Mycontext);
Image_Cookie.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

lastPoint = currentPoint;