2

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?

Mundi
  • 79,884
  • 17
  • 117
  • 140
rkb
  • 10,933
  • 22
  • 76
  • 103
  • I figured it out.. change the line of CGContextFillRect to. CGContextFillRect(ctx, CGRectMake(0, 0, baseImage.size.width, 100)); – rkb Jul 29 '09 at 18:17

1 Answers1

1

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

rkb
  • 10,933
  • 22
  • 76
  • 103