0
嗨朋友, 我正在開發彩色填充遊戲。我知道如何着色全圖像,但我想在透明區域着色圖像。如何在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;
}
如何找到透明區域的圖像中填充的顏色..?
你可以給一些示例代碼。 – banu
我在做繪畫app.so我想應用Floodfill算法 – banu
你有沒有任何示例代碼 –