Iphone app: how to fill image with blank areas using coregraphics?

I am starting to develop applications for Iphone and wondering if the following can be done:

I have a .png image, which is a simple drawing of a shape bounded by black edges and empty areas. I wonder if there is a method or mode for filling closed empty areas of the image.

It looks like a MSpaint filling pot.

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 do not know what to do to fill out ...

I would really appreciate it if someone could answer this question. Thank you very much!

+4
source share
1 answer

I have an image ... which ... is limited by black edges and empty areas.

If by β€œempty” you mean that these areas have alpha zero, first fill in the context of the desired color (filling in the entire area of ​​the context), and then draw the image on top. Color will be displayed where the image is transparent, and not where it is missing.

A closer match to the request would be to draw an image in copy overlay mode, and then fill in the color in source blend mode.

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

0
source

All Articles