我是iPhone新手。我有一個任務,我需要用手指畫一張照片。沒有什麼奇特的,只有一種顏色的寬度(siganture)。任何人都可以指出實現這一目標的最佳方式嗎? TNX在照片上繪圖
Q
在照片上繪圖
0
A
回答
0
請參閱此鏈接....雖然這個問題被關閉的解決方案是正確的。 https://stackoverflow.com/questions/11828200/writing-with-finger-on-iphone/11828810#11828810
請參閱該代碼。我已經使用UITouch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = NO;
UITouch *touch = [[event touchesForView:baseView]anyObject];
lastPoint = [touch locationInView:drawingView];
}
// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
mouseSwiped = YES;
UITouch *touch = [[event touchesForView:baseView] anyObject];
CGPoint currentPoint = [touch locationInView:drawingView];
//currentPoint.y -= 20;
UIGraphicsBeginImageContext(drawingView.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, drawingView.frame.size.width, drawingView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
if (eraserSelected)
{
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
}
[self changeBrushColor];
//[self changeBrushColor:segmentedControl];
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext() , lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
// Handles the end of a touch event when the touch is a tap.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//UITouch *touch = [[event touchesForView:self.view] anyObject];
/*
if ([touch tapCount] == 2)
{
imgView.image = nil;
return;
}
*/
if(!mouseSwiped) {
UIGraphicsBeginImageContext(drawingView.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, drawingView.frame.size.width, drawingView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
[self changeBrushColor];
//[self changeBrushColor:segmentedControl];
//CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext() , lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
CGContextFlush(UIGraphicsGetCurrentContext());
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
- (void)changeBrushColor
{
switch (selectedColor) {
case 1:
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
break;
case 2:
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.45, 0.87, 0.04, 1.0);
break;
0
我創建了你想要的演示,下面是它的代碼。
CGPoint midPoint(CGPoint p1, CGPoint p2)
{
return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5);
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
previousPoint1 = [touch previousLocationInView:self];
previousPoint2 = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
[self touchesMoved:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
// calculate mid point
CGPoint mid1 = midPoint(previousPoint1, previousPoint2);
CGPoint mid2 = midPoint(currentPoint, previousPoint1);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, mid1.x, mid1.y);
CGPathAddQuadCurveToPoint(path, NULL, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGRect bounds = CGPathGetBoundingBox(path);
CGPathRelease(path);
CGRect drawBox = bounds;
//Pad our values so the bounding box respects our line width
drawBox.origin.x -= self.lineWidth * 2;
drawBox.origin.y -= self.lineWidth * 2;
drawBox.size.width += self.lineWidth * 4;
drawBox.size.height += self.lineWidth * 4;
UIGraphicsBeginImageContext(drawBox.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
curImage = UIGraphicsGetImageFromCurrentImageContext();
[curImage retain];
UIGraphicsEndImageContext();
[self setNeedsDisplayInRect:drawBox];
}
- (void)drawRect:(CGRect)rect
{
[curImage drawAtPoint:CGPointMake(0, 0)];
CGPoint mid1 = midPoint(previousPoint1, previousPoint2);
CGPoint mid2 = midPoint(currentPoint, previousPoint1);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
CGContextStrokePath(context);
[super drawRect:rect];
[curImage release];
}
You also Download the source code for Here.
我認爲這幫助了這麼多。
快樂編碼。
相關問題
- 1. android在照片上畫圖
- 2. 搜索一張照片進行繪圖
- 3. 在Android上的繪圖圖片
- 4. 安排在地圖上的照片
- 5. 使用PHP在Facebook上上傳圖片或照片
- 6. 從Google照片上傳多張照片
- 7. 在網頁上繪製任意圖片
- 8. 在android中的圖片上繪製
- 9. 如何在圖片上繪製文字?
- 10. 在html繪圖工具中用照片替換顏色
- 11. 上傳照片在ASP
- 12. 在asp.net上傳照片
- 13. 在iPhone上顯示照片
- 14. 在牆上張貼照片
- 15. 如何在照片打開後在照片上放置鏈接?
- 16. 如何通過圖形api上傳照片,但當照片在服務器外?
- 17. 如何在CodeName One中的圖片上繪製圖片?
- 18. 在asp.net網站上顯示圖片/照片
- 19. 如何在圖片照片上肩膀本地化?
- 20. 照片上傳CodeIgniter
- 21. PhotobucketNet照片上傳
- 22. Plixi上傳照片
- 23. iOS上傳照片
- 24. 照片不上傳
- 25. Android:上傳照片
- 26. facebook上傳照片
- 27. Dropbox照片上傳
- 28. facebook圖api檢索牆上的照片
- 29. iphone照片上傳 - PHP&Jqtouch圖書館
- 30. Facebook API圖和上傳照片
你能給我們一些你已經有的代碼樣本嗎?或者你想如何以更具體的方式做到這一點? – hifkanotiks 2012-08-14 13:18:05