How to achieve paint brush strokes in iOS - ios

I am developing an iOS app that uses a paint brush to draw in a board. I have created a simple paint tool with which user can paint,but what I really need is a paint tool that draws with brush stroke. Is there anyway to achieve the same in native iOS app development?
Here is a sample image of the brush stroke I would like to create:

the fact is you'll have to go to GLPaint
https://developer.apple.com/library/ios/samplecode/GLPaint/Introduction/Intro.html
consider also https://github.com/rbuussyghin/glpaint
and https://stackoverflow.com/a/2045262/294884
this is not easy.
Indeed, it's a huge P.I.T.A. Surprisingly, nobody has a ready-made solution for this in iOS.
For 2019 ...
Surprisingly, as far as I know, there is STILL no ready-made solution for this. Strange thing!
For 2021 ...
Appears there are finally some libraries in Metal, example
https://github.com/Harley-xk/MaLiang

Related

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.
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.

Recreate Photoshop's "mixer brush tool" for painting iOS app

I'm attempting to create a painting app for iOS. One feature I hope to have is like Photoshop's "Mixer Brush Tool." In Photoshop you can adjust the wetness, mix and flow of the brush.
I looked at all the core image effects, even the distortion effects but did not see anything similar. Anyone know of any sample code that does this? If not, any direction to guide me through would be great. I'm stuck at the moment.

2013, Existing package for drawing (painting, brush, lines) in iOS?

I need to add typical finger drawing to an app.
(The usual.... choose colors, erase, thickness - just the usual you see in every app made.)
It's hard to believe I have to program this from scratch, in this day and age?
It's hard to believe there is not a common solution for this?
All I could find is...
https://github.com/levinunnink/Smooth-Line-View
Review: that is a (beautifully written) example fragment of a few lines of code being how to draw with a path, with a good smooth result. It works perfectly, but it's just for drawing one "path." For example, you can't make a drawing with more than one color. there is no undo or anything like that. (See also note on the fourth review item here regarding path-math.)
https://github.com/sumanthk2006/Smooth-Line-View-1 (variation of above, but does not run under ARC, unfortunately demo does not properly launch etc)
Review: this is "abandonedware" or maybe "frustrationware" :) It does not run and is not ARC-ready. It is a seemingly well-written class that claims to do undo, colors, erase, etc. It even has a proper delegate to track your button states. But it doesn't work.
UPDATE Regarding this paackage. As a matter of fact, if you massage it it works well. Suggest (i) throw away the example app files. (ii) using modern Xcode, use the "convert to ARC project" feature on the two main files. There are a coupe little problems like it should use awakeFromNib. If you get it working it actually does everything, really well.
THERE ARE SERIOUS BUGS in SmoothLineView1. just to be clear, it suffers some serious bugs - you'll see there's a "streaking" effect when you draw.
http://www.cdframeworks.com/product/brushengine
Review: This commercial package (under $100) is well made and email support is fast. Unfortunately it does not have undo so it's not suitable for many situations. (Also does not have erase.)
Mentioned below is this popular article:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/
Review: this is a good article on the actual TECHNOLOGY of drawing curves, on the let's say "path-math". Unfortunately it's no help at all if you need a working, ready to use, drawing package (with the obvious features, undo, erase, colors etc) to use in an iOS app. Thus for example, whatever actual solution you were using, you may, perhaps, want to apply the math concepts in this article.
I appreciate that the basic concepts are very simple, it's easy enough to "start from scratch". But it's just - ridiculous - to have to do from scratch for something so commonplace. Is there a solid package I'm missing?
It's fairly amazing that the four scratchy references above are the only things out there.
Any ideas? What's the best package today (late 2013) for adding drawing to an iOS app? THANKS.
As of 2017, I use https://github.com/acerbetti/ACEDrawingView/.
It can be used through cocoa pods, and provide full functionality over integrating a drawing feature in your app (color, brush, size, eraser, undo/redo/, etc).
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/ has a good, clear tutorial on smooth freehand drawing on the ios. If you just follow the tutorial, you can implement it easily into whatever app you are trying to make. It has stuff about increasing line quality and smoothness, and stroke quality.http://www.raywenderlich.com/18840/ is another tutorial on a simple drawing app, self-contained. You can combine aspects of both to get what you want.
edit: https://developer.apple.com/library/ios/samplecode/GLPaint/Introduction/Intro.html is the GLPaint sample provided by apple, which includes detecting shake. I thought it seemed more official, since it's from apple
to answer your question, there is no package for drawing directly, but there is a UIKit class, UIBezierPath, that lets you draw shapes made of straight lines or some curves.

Any idea about simulating the stroke in iOS Paint app?

I'm working on an paint app for iOS platform.And I used CGContextAddQuadCurveToPoint to make the line more smooth. But I'm stuck in how to simulate the stroke.
Papers 53 is a really cool app. I just wanna simulate the stroke just like what 'Papers 53' does.
Any idea about changing the width of the line dynamically and smoothly during drawing?
I found an article about this stuff.
http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/
This one is really reliable and I just used its algorithm to simulate smooth stroke by using Quartz2d successfully.

Improving Drawing Performance (for Dudel application)

I needed to create a small drawing/paint application, so i turned to Beginning IPad Development for IPhone Developers: Mastering the IPad SDK By Jack Nutting, Dave Wooldridge, David Mark.
It's pretty nice. The architecture is strong. But, the drawing application (Dudel) is not very good in terms of performance. There are two main issues (for me, at the moment):
Most Important: The drawing slows down after a while. Reason: drawRect is being called, every time, for all the paths.
The drawing with Pencil tool isn't smooth. Reason: It's using addLineToPoint: instead of (may be) addQuadCurveToPoint:.
There's no Eraser control. But it's really not an issue, because we can choose white color for the painting go give an illusion of an eraser. But, if there's a better implementation for that, i'm interested to know.
Question:
Is there a solution out there that addresses these issues, and provide a simple but efficient drawing application?
Note: I need the Undo/Redo feature as well.
Let me try to answer your question one by one.
The drawing with Pencil tool isn't smooth. Reason: It's using addLineToPoint: instead of (may be) addQuadCurveToPoint:.
What you say is true.IOS device looks for touches in a defined interval. If you move your hand fast, it is very likely that you may end up losing few touch points . Hence connecting points using lines results in ugly spikes.
We can smooth the curve by curve fitting algorithms.However Some tweaks in the drawing can result in measurable improvement in quality. Here is an example for it.
Eraser control
If you know the background color you can use that as brush color to give an eraser feeling. if you do not know the background you can use
CGContextSetBlendMode(context, kCGBlendModeClear);
Undo/Redo
you can use NSUndoManager .

Resources