开发者

Iphone App: How to fill an image with empty areas with coregraphics?

开发者 https://www.devze.com 2023-01-20 12:06 出处:网络
I\'m a beginner developing apps for Iphone and was wondering if is possible to do the following: I have an image .png wich is a simple draw of a figure bounded with black edges and empty areas. I won

I'm a beginner developing apps for Iphone and was wondering if is possible to do the following:

I have an image .png wich is a simple draw of a figure bounded with black edges and empty areas. I wonder if there is a method or a mode to fill the closed empty areas of the image.

Its like as the pot of MSpaint filling.

I have this code:

CGContextRef ctx = UIGraphicsGetCurrentContext();
UIImage *image = [UIImage imageNamed:@"myImage.png"];
CGContextDrawImage(context, CGRectMake(0, 0, 145, 15), image.CGImage);
[image drawInRect:CGRectMake(0, 0, 145, 15)];

Now i don't know what to do to fill...

I'll be very grateful if someo开发者_如何学编程ne can answer this question. Thank you very much!


I have an image … wich is … bounded with black edges and empty areas.

If by “empty” you mean these areas have alpha zero, simply fill the context with the desired color (filling the entire extent of the context) first, then draw the image on top. The color will show through where the image is transparent, and not where it isn't.

A closer match to what you asked for would be to draw the image using the Copy blend mode, then do the color fill using the Source Out blend mode.

Blend modes are your friend; learn them well, because you can do a lot with them.

0

精彩评论

暂无评论...
验证码 换一张
取 消