2
我使用下面的代碼來填充顏色iPhone的圖像在圖像的一部分。如何填充顏色只在在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;
}
但上面的代碼填充整個圖像中的顏色。我只想感受上半部分,比如圖像的1/4。那麼該怎麼做呢?
我想通了.. 變化CGContextFillRect到的線。 CGContextFillRect(ctx,CGRectMake(0,0,baseImage.size.width,100)); – rkb 2009-07-29 18:17:52