views:

446

answers:

1

Hello all,

I am using the following code to fill color in an image in 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;

}

But the above code fills the color in the whole image. I just want to feel upper part, say 1/4th of the image. So how to do it.

A: 

I figured it out.. change the line of CGContextFillRect to. CGContextFillRect(ctx, CGRectMake(0, 0, baseImage.size.width, 100));

rkb