2011-06-21 5 views
2

これまでは図面があります。私は色々なボタンを持っていますが、色を変える方法がわかりません。CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext)

@interface GameScreen : UIViewController { 

    BOOL mouseSwiped; 
    float lineWidth; 
    CGPoint lastPoint; 
    IBOutlet UIImageView *drawImage; 
} 
@end 

.M:

#import "GameScreen.h" 
#import "DoodlePicViewController.h" 
#import "Settings.h" 

@implementation GameScreen 

@synthesize theimageView,choosePhoto, takePhoto; 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = NO; 
    UITouch *touch = [touches anyObject]; 
    lineWidth = thickness.value; 

    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.view]; 
    currentPoint.y -= 20; 


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

    lastPoint = currentPoint; 



} 



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

    UITouch *touch = [touches anyObject]; 


    if(!mouseSwiped) { 
     UIGraphicsBeginImageContext(self.view.frame.size); 
     [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth); 
     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()); 
     drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
    } 
} 


@end 
私はすべてのRGBカラーコードを持っていますが、どのように私はIBActionとなるようにそれを作るのですか、それは CGContextSetRGBStrokeColor UIGraphicsGetCurrentContext()

の.hを変更します

私は本当にそれを理解しようとしているが、私は立ち往生している☹

+0

ドローイングは機能していますが、おそらく2つのボタンに基づいたユーザー入力に基づいてそれを変更したいのですか? –

答えて

1

私はthiスライダーの値をfromm 0から1にすることができます.3スライダーの値を取得し、CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext()、1.0、1.0、1.0、1.0)に渡すことができます。それも同様に行うことができます。私はIBが良いことだとは思わない。

関連する問題