2009-07-29 10 views
2

J'utilise le code suivant pour remplir la couleur dans une image dans l'iPhone.Comment remplir la couleur dans seulement une partie de l'image dans l'iPhone

- (UIImage *)colorizeImage:(UIImage *)baseImage color:(UIColor *)theColor { 
UIGraphicsBeginImageContext(baseImage.size); 

CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height); 

CGContextScaleCTM(ctx, 1, -1); 
CGContextTranslateCTM(ctx, 0, -area.size.height); 

CGContextSaveGState(ctx); 
CGContextClipToMask(ctx, area, baseImage.CGImage); 

[theColor set]; 
CGContextFillRect(ctx, area); 

CGContextRestoreGState(ctx); 

CGContextSetBlendMode(ctx, kCGBlendModeMultiply); 

CGContextDrawImage(ctx, area, baseImage.CGImage); 

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 

return newImage; 

}

Mais le code ci-dessus remplit la couleur dans l'image. Je veux juste me sentir en haut, disons 1/4 de l'image. Alors, comment le faire?

+0

Je l'ai compris .. changer la ligne de CGContextFillRect à. CGContextFillRect (ctx, CGRectMake (0, 0, baseImage.size.width, 100)); – rkb

Répondre

1

Je l'ai trouvé .. changez la ligne de CGContextFillRect à. CGContextFillRect (ctx, CGRectMake (0, 0, baseImage.size.width, 100));

+0

bien répondre à ce problème-http: //stackoverflow.com/questions/8124308/filling-a-portion-of-an-image-with-color – Marios

+0

Ceci est pour CGRECT mais si l'image est dans une autre forme alors whay faire? ? –

Questions connexes