2013-01-07 4 views
0

안녕하세요 친구, 나는 full.but 전체 영역에서 색상을 지정하는 방법을 알고 coloring game.i 채우기를 개발 중입니다 투명 영역에서 이미지를 채색하고 싶습니다. 여기ios에서 uiimage의 투명 영역을 찾는 방법은 무엇입니까?

색상 이미지에 대한 내 코드

-(UIImage*)setCollor:(UIColor*)color image:(UIImage*)img 
{ 
    UIGraphicsBeginImageContext(img.size);  
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    // set the fill color 
    [color setFill]; 

    CGContextTranslateCTM(context, 0, img.size.height); 
    CGContextScaleCTM(context, 1.0, -1.0); 

    // set the blend mode to color burn, and the original image 
    CGContextSetBlendMode(context, kCGBlendModeColorBurn); 
    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height); 
    CGContextDrawImage(context, rect, img.CGImage); 

    // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle 
    CGContextClipToMask(context, rect, img.CGImage); 
    CGContextAddRect(context, rect); 
    CGContextDrawPath(context,kCGPathFill); 

    // generate a new UIImage from the graphics context we drew onto 
    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    //return the color-burned image 
    return coloredImg; 
} 

어떻게 색상을 이미지에 투명 영역을 찾아 채우기 위해 ..?

답변

0

먼저 완전한 직사각형을위한 색을 채우십시오. rect는 크기 이미지 너비와 이미지 높이가됩니다. 이제 같은 rect에 이미지를 그립니다.

CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
    CGContextFillRect(context, rect); 

    CGContextDrawImage(context, rect, [UIImage imageNamed:@"myImage"].CGImage); 
+0

몇 가지 샘플 코드를 제공 할 수 있습니까? – banu

+0

그림을 그리는 중 app.so입니다. floodfill 알고리즘을 적용하고 싶습니다. – banu

+0

이 예제 코드가 있습니까? –

관련 문제