Although it doesn't directly answer your question, you may be able to get the effect you are looking for by using the kCGBlendModeLuminosity
blend mode:
- (void)drawRect:(CGRect)rect {
CGSize imageSize = [image size];
CGContextRef c = UIGraphicsGetCurrentContext();
if (isGrey)
CGContextSetBlendMode(c, kCGBlendModeLuminosity);
CGContextScaleCTM(c, 1.0, -1.0);
CGContextDrawImage(c, CGRectMake(0.0f, 0.0f, imageSize.width, -imageSize.height), [image CGImage]);
}
Also, the rect passed to drawRect:
is the invalid area, not the entire area. You should be using the bounds
instead