2013-03-26 30 views
1

我是iOS編程新手,我搜索了很多核心圖像鏈接,答案和教程,但我仍然不完全明白。我有一個測試應用程序誰有按鈕,容易的東西,我有圖像,當我按下一些過濾器按鈕,它使過濾器和顯示它。我如何在ciimage中繪製方形或圓形圓形的眼睛和嘴巴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){} 
} 

現在我有一個問題(我不知道這是否是正確的開始)。請幫我想知道怎麼做next..thank你提前

回答

1

如何(沒有編制,但應該接近):

for (CIFaceFeature *faceFeature in features){ 
     CGRect faceRect = faceFeature.bounds; 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetLineWidth(context, 1.0); 

    CGContextAddRect(context, faceRect); 
    CGContextDrawPath(context, kCGPathStroke); 
} 
+0

另外,確保添加#進口 2013-03-26 13:53:13

+0

如果你需要按鈕,你也可以使用faceFeature.bounds矩形創建UIButtons,但是這應該給你一個總體思路。 – 2013-03-26 13:54:53

+0

謝謝歐文現在我得到的錯誤CGContextAddRect:無效的情況下爲0x0 CGContextDrawPath:無效的情況下爲0x0 CGContextSetLineWidth:無效的情況下爲0x0 再次感謝 – userDC 2013-03-26 15:18:01