如何在 uiimage iOS 中围绕眼睛和嘴巴绘制正方形或圆形
Posted
技术标签:
【中文标题】如何在 uiimage iOS 中围绕眼睛和嘴巴绘制正方形或圆形【英文标题】:how can i draw square or circle arround eyes and mouth in ciimage iOS 【发布时间】:2013-03-16 04:24:45 【问题描述】:我是 ios 编程新手,我已经搜索了很多核心图像链接、答案和教程,但我仍然不太了解。我有一个带有按钮的测试应用程序,简单的东西,当我按下某个过滤器按钮时,它会生成过滤器并显示它。
CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"pic1.JPG"]];
CIFilter *colorControls = [CIFilter filterWithName:@"CIColorControls"];
[colorControls setValue:inputImage forKey:@"inputImage"];
[colorControls setValue:[NSNumber numberWithFloat:0.5f] forKey:@"inputSaturation"];
[colorControls setValue:[NSNumber numberWithFloat:0.8f] forKey:@"inputContrast"];
[colorControls setValue:[NSNumber numberWithFloat:0.4f] forKey:@"inputBrightness"];
CIImage *outputImage = [colorControls valueForKey:@"outputImage"];
CIContext *context = [CIContext contextWithOptions:nil];
theImageView.image = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];
现在我想要一个按钮,它可以检测眼睛和嘴巴并在其周围绘制矩形或圆形,无论是什么颜色和什么颜色都没有关系。我一直到
- (IBAction)detectFace:(id)sender
CIImage *inputImage = [[CIImage alloc]initWithImage:[UIImage imageNamed:@"pic1.JPG"]];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSArray* features = [detector featuresInImage:inputImage];
for (CIFaceFeature *faceFeature in features)
现在我遇到了一个问题(我不确定这是否是正确的开始)。请帮助我想知道下一步该怎么做..提前谢谢你
【问题讨论】:
【参考方案1】:怎么样(还没编译,但应该很接近):
for (CIFaceFeature *faceFeature in features)
CGRect faceRect = faceFeature.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
CGContextAddRect(context, faceRect);
CGContextDrawPath(context, kCGPathStroke);
【讨论】:
另外,确保添加#import以上是关于如何在 uiimage iOS 中围绕眼睛和嘴巴绘制正方形或圆形的主要内容,如果未能解决你的问题,请参考以下文章
iOS - 我如何只在 UIView 上更新我的 UIImage