0

I'm considering building an app that would make heavy use of a flood fill / paint bucket feature. The images I'd be coloring are simply like coloring book pages; white background, black borders. I'm debating which is better to use UIImage (by manipulating pixel data) or drawing the images with Core Graphics and changing the fill color on touch.

With UIImage, I'm unable to account for retina images properly; it destroys the image when I write the context into a new UIImage, but I can probably figure out. I open to tips though...

With CoreGraphics, I have no idea how to calculate which shape to fill when a user touches an area and then actually filling that area. I've looked but I have not turned up a successful search.

Overall, I believe the optimal solution is using CoreGraphics, since it'll be lighter overall and I won't have to keep several copies of the same image for different sizes.

Thoughts? Go easy on me! It's my first app and first SO question ;)

Rob
  • 4,927
  • 12
  • 49
  • 54
hjin-sun
  • 3
  • 2

1 Answers1

1

I'd suggest using Core Graphics.

Instead of images, define the shapes using CGPath or NSBezierPath, and use Core Graphics to stroke and/or fill the shapes. Filling shapes is then as easy as switching drawing mode from just stroking to stroking and filling.

Creating even more complex shapes is made much easier with the "PaintCode" app (which lets you draw and creates the path code for you).

As your first app, I would suggest something with a little less custom graphics fiddling, though.

fzwo
  • 9,842
  • 3
  • 37
  • 57
  • Definitely. However, `CGImageRef` with bitmap context would be possible, too. Modifying the bytes directly would be fast. Using `UIImage` for something else then static images or saving the resulting file would be terrible from perfomance perspective. – Sulthan Mar 11 '13 at 15:48
  • thanks fzwo and Sulthan. one thought i had is that with using CoreGraphics and something like PaintCode, each "image" is a class unto itself, which means that whenever i add new images to the app i'd have to rebuild and reship as an update, right? using bitmaps over vectors, i'd be able to dynamically import them into the app using a custom API that fetched new images. Sulthan, i do plan on using UIImage for just static images. i did a prototype converting a uiimage to a cgimageref, manipulating the pixels and plugging the bitmap context back into a uiimage. is that what you mean? – hjin-sun Mar 12 '13 at 02:27
  • You could conceivably load an XML, JSON or other descriptive file containing the points and control points to create an `NSBezierPath` from a server with without having to update the app. I am not sure though if this might go against any guidelines Apple has for the store that forbid downloading of "executable" data, so if you want to go this route, better ask an the Apple Dev Forums about it. – fzwo Mar 12 '13 at 08:14