Translate

2012年7月19日 星期四

UIImage to UIColor and UIColor to UIImage

UIImage *imgpattern = [UIImage imageNamed:@"box_bg.png"]; [info_sv setBackgroundColor:[UIColor colorWithPatternImage:imgpattern]];
- (UIImage *) createImageWithColor: (UIColor *) color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage; }

沒有留言:

張貼留言