Mon problème: la couleur du carré de remplissage passe du noir au bleu (255) sans couleur de transition (bleu foncé, bleu foncé, bleu ...). Il semble que CGContextSetRGBStroke est additif (WTF Oo). comme si le bleu avait 14 ans et la prochaine mise à jour je mets 140 le bleu sera de 154 et pas 140 ai-je mis.CGContextSetRGBFillColor ne règle pas la bonne couleur
Est-ce que quelqu'un a ce problème?
dans le .h
CGFloat angle;
int width;
int height;
NSTimer* timer;
CGPoint touch;
dans le .m
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
angle=0;
width = frame.size.width;
height= frame.size.height;
//self.backgroundColor=[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:1];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(update:) userInfo:nil repeats:YES];
}
return self;
}
-(void)update:(NSTimer*)theTimer
{
[self setNeedsDisplay];
}
NS_INLINE CGFloat radians(CGFloat ang)
{
return ang*(M_PI/180.0f);
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx=UIGraphicsGetCurrentContext();
//CGContextSetRGBFillColor(ctx, -1,-1,-1,-1);
CGContextSaveGState(ctx);
CGRect ourRect = CGRectMake(40+angle, 40+angle, 240, 120);
CGFloat colour=(touch.y/768)*255;
NSQLog(@"draw %f",colour);
CGContextSetRGBFillColor(ctx, 0.0,0.0,colour,1);
CGContextClearRect(ctx, rect);
CGContextFillRect(ctx, ourRect);
CGContextSetRGBStrokeColor(ctx, 0.0, 1.0, 0.0, 1.0);
CGContextStrokeRectWithWidth(ctx, ourRect, 10);
CGContextRestoreGState(ctx);
angle+=1;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
touch= [[touches anyObject] locationInView:self];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
touch= [[touches anyObject] locationInView:self];
}
VRAI !!! J'utilisais Processing pour tester le code graphique et j'oublie de changer la couleur de la gamme 0-255 en 0-1. Thks ... 1 jour pour le trouver ... Sincèrement thk – xeonarno
Si mon message était utile, soin de le marquer comme la réponse acceptée? –