CGContextSetRGBStrokeColor (UIGraphicsGetCurrentContext)

Пока у меня есть рисунок. У меня есть разные цветные кнопки, но я не знаю, как изменить их цвета. У меня есть все цветовые коды 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

Я действительно пытаюсь понять это, но я застрял ☹


person Mateo E    schedule 21.06.2011    source источник
comment
Итак, у вас есть рабочий рисунок, но вы хотите изменить его в зависимости от пользовательского ввода, который, вероятно, основан на паре кнопок, верно?   -  person Deepak Danduprolu    schedule 21.06.2011


Ответы (1)


Я думаю, вы можете использовать ползунок, так как его значение от 0 до 1. И вы можете получить значения 3 ползунков, а затем передать их в CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),1.0, 1.0, 1.0, 1.0), без IB Вы также можете это сделать. Я не думаю, что IB это хорошо.

person Henry Zhang    schedule 18.05.2012