Search code examples
ipadios13swift5metalxcode11

Best approach for coding a painting app on iOS / iPad


I’m trying to build a drawing/painting app for the iPad, with textured brush tips and paper.

So far, all drawing app example codes I've come across seem to work by stroking a path. However, I'd like to actually apply a texture all along the path, to simulate say, an oil brush, or charcoal.

Here is an example of a brush tip texture: Bursh tip

The result when painting with the same brush tip: Result

In the results, the top output is what it looks like when the "brush tip" texture is applied far apart along the path.

The bottom result is the texture applied with very small steps along the path. Those who've worked in Photoshop with custom brushes will find this familiar.

I had once prototyped this in Processing years ago (I've since lost the source code), and got it to work in real-time.

In Processing, I converted both the brush tip PNG and the canvas (or the image I'm painting on to) into an array of integers. Then, I simply copied the values from the brush tip to the canvas texture, at the appropriate index. At the end of the cycle, I displayed the image, for that time-step. Repeat this dozens of times in-between each point returned by the mouse.

How would I approach this in iOS, and in real-time? I tried this (https://blog.avenuecode.com/how-to-use-uikit-for-low-level-image-processing-in-swift) but it's way too slow.

This makes me believe Metal might be the only way forward. Is that true, or am complicating this unnecessarily?

Thank you for any guidance!

PS. I'm coding in Swift 5, targeting iOS 13, in Xcode 11.5.


Solution

  • Welcome!

    I recommend you check out Core Image. It's Apple's framework for image processing (on a higher level than Metal, though it can integrate with Metal). Unfortunately, the documentation is a bit out-dated, but I'm sure you can translate it into Swift.

    Here Apple describes how you would realize a painting app with Core Image and here you can download the corresponding sample project.