CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext)

时间:2011-06-21 14:15:53

标签: iphone xcode cocoa-touch core-graphics

到目前为止,我有一张图纸。我有不同的颜色按钮,但我不知道如何改变它们的颜色。我有所有的RGB颜色代码,但如何使用IBAction进行更改,它会更改CGContextSetRGBStrokeColor UIGraphicsGetCurrentContext()

·H

@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

我真的想弄清楚,但我被困了☹

1 个答案:

答案 0 :(得分:1)

我认为你可以使用一个滑块,因为它的值是从0到1.你可以得到3个滑块的值,然后将它们传递给CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0,1.0,1.0,1.0)没有IB,你也可以这样做。我认为IB不是一件好事。