2010-09-21 2 views
2
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(); 

Я использую этот код для рисования ...... В касании.проблема в черновой линии

У меня есть пробелы, когда ям рисует быстро ... что делать?

ответ

2

Вы должны использовать метод previousLocationInView: UITouch, чтобы получить предыдущую известную точку, в которой находился ваш палец, и нарисовать линию между этой точкой и текущим местоположением.

Другое решение - сохранить текущую точку в статической переменной между двумя вызовами.

+0

@vdsmedT .... CGPoint currentPoint = [touch previousLocationInView: self.view]; если я использовал это в touchhesMoved, это не изменилось .... – kiran

+0

CGPoint prevPoint = [touch previousLocationInView: self.view]; CGPoint curPoint = [touch locationInView: self.view]; – VdesmedT

+0

@vdsmedT .... Я использовал previouslocationInView тоже ....... все еще я получаю пробелы при рисовании iam. – kiran

1
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; 
+0

@brad larson ....... Спасибо .... Можем ли мы еще оптимизировать его .... – kiran

Смежные вопросы