2011-11-21 76 views
1

我是iPad應用程序開發新手。如何創建一個允許用戶自由繪製的應用程序?

我有任務開發像iDesk應用程序的應用程序,我不知道如何從應用程序開始。

此應用程序有1.徒手畫2.形狀識別&更多的功能。但我不知道如何從這個應用程序開始。 請幫助我。

提供了一些關於如何創建這個應用程序的細節。我認爲這個應用程序是從openGL創建的。如果可能,請提供一些樣品。

請幫幫我。

我已經張貼了關於這個話題New Question for this topic

請幫我這個新問題。

+6

Urhm,恐怕你要求我們告訴你如何編寫你的應用程序。去看看一些教程。詳細瞭解應用程序開發。如果你不知道如何開始某件事,那麼這是一個你不知道該做什麼的好跡象。 – CommunistPancake

+0

http://stackoverflow.com/questions/how-to-ask – Krishnabhadra

+0

可能重複的[iOS開源繪圖應用程序源代碼](http://stackoverflow.com/questions/4121184/ios-open-source-drawing-應用程序的源代碼) –

回答

1

使用我剛纔用它下面。它會明確地工作: -

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    mouseSwiped = NO; 
    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
     [drawImage setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"white" ofType:@"png"]]]; 
     return; 
    } 

    lastPoint = [touch locationInView:self.view]; 
    lastPoint.y -= 20; 

} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = YES; 

    UITouch *touch = [touches anyObject]; 
    CGPoint currentPoint = [touch locationInView:self.drawImage]; 
    currentPoint.y -= 20; 

    NSLog(@"current Point is x: %d, y: %d",currentPoint.x,currentPoint.y); 

    UIGraphicsBeginImageContext(self.drawImage.frame.size); 
    [drawImage.image drawInRect:CGRectMake(0, 0, self.drawImage.frame.size.width, self.drawImage.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.5, 0.6, 1.0); 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    lastPoint = currentPoint; 

} 
4

這是我用於繪製的UIView子類。我不記得在哪裏採購它,如果任何人識別代碼,請給予信貸原來的程序員:

#import <UIKit/UIKit.h> 
#import <QuartzCore/QuartzCore.h> 



@interface SignatureView : UIView { 
     UIImage *myPic; 
    } 

    @property (strong, nonatomic) NSMutableArray *myDrawing; 
    @property (nonatomic) BOOL canDraw; 

    - (void) drawPic:(UIImage*)thisPic; 
    - (void) cancelDrawing; 
    - (UIImage*) collectSignature; 

    @end 




    #import "SignatureView.h" 

    @implementation SignatureView 

    @synthesize canDraw, myDrawing; 

    - (void)drawRect:(CGRect)rect 
    { 
    //round the corners 
    self.layer.cornerRadius = 5; 
    self.clipsToBounds = YES; 

    float newHeight; 
    float newWidth; 
    if (!myDrawing) 
     myDrawing = [[NSMutableArray alloc] initWithCapacity:0]; 

    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    if (myPic != NULL) 
    { 
     float ratio = myPic.size.height/460; 
     if (myPic.size.width/320 > ratio) 
     { 
      ratio = myPic.size.width/320; 
     } 
     newHeight = myPic.size.height/ratio; 
     newWidth = myPic.size.width/ratio; 
     [myPic drawInRect:CGRectMake(0,0, newWidth, newHeight)]; 
    } 
    if ([myDrawing count] > 0) 
    { 
     CGContextSetLineWidth(ctx, 5); 
     for (int i = 0; i < [myDrawing count]; i++) 
     { 
      NSArray *thisArray = [myDrawing objectAtIndex:i]; 
      if ([thisArray count] > 2) 
      { 
       float thisX = [[thisArray objectAtIndex:0] floatValue]; 
       float thisY = [[thisArray objectAtIndex:1] floatValue]; 
       CGContextBeginPath(ctx); 
       CGContextMoveToPoint(ctx, thisX, thisY); 
       for (int j = 2; j < [thisArray count] ; j+=2) 
       { 
        thisX = [[thisArray objectAtIndex:j] floatValue]; 
        thisY = [[thisArray objectAtIndex:j+1] floatValue]; 
        CGContextAddLineToPoint(ctx, thisX,thisY); 
       } 
       CGContextStrokePath(ctx); 
      } 
     } 
    } 
} 

- (void)drawPic:(UIImage *)thisPic 
{ 
    myPic = thisPic; 
    [self setNeedsDisplay]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [myDrawing addObject:[[NSMutableArray alloc] initWithCapacity:4]]; //memory leak 
    CGPoint curPoint = [[touches anyObject] locationInView:self]; 
    [[myDrawing lastObject] addObject:[NSNumber numberWithFloat:curPoint.x]]; //memory leak 
    [[myDrawing lastObject] addObject:[NSNumber numberWithFloat:curPoint.y]]; //memory leak 
} 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGPoint curPoint = [[touches anyObject] locationInView:self]; 
    [[myDrawing lastObject] addObject:[NSNumber numberWithFloat:curPoint.x]]; //memory leak 
    [[myDrawing lastObject] addObject:[NSNumber numberWithFloat:curPoint.y]]; //memory leak 
    [self setNeedsDisplay]; 
} 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGPoint curPoint = [[touches anyObject] locationInView:self]; 
    [[myDrawing lastObject] addObject:[NSNumber numberWithFloat:curPoint.x]]; 
    [[myDrawing lastObject] addObject:[NSNumber numberWithFloat:curPoint.y]]; 
    [self setNeedsDisplay]; 
} 

-(void)cancelDrawing 
{ 
    [myDrawing removeAllObjects]; 
    [self setNeedsDisplay]; 
} 

- (UIImage *)collectSignature 
{ 
    //take screenshot 
    UIGraphicsBeginImageContext(self.bounds.size); 
    [self.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return viewImage; 
} 

@end 
+0

非常感謝你..這幫了我很多.. :-) – ArunaFromLK

+0

很高興幫助@ArunaLakmal :) – bennythemink

相關問題