gpt4 book ai didi

iphone - CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext)

转载 作者:行者123 更新时间:2023-12-03 21:19:17 24 4
gpt4 key购买 nike

到目前为止我已经有一幅画了。我有不同颜色的按钮,但我不知道如何更改它们的颜色。我有所有的 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

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

最佳答案

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

关于iphone - CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6426766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com