objective-ccocoabrushes

Cocoa : Creating Oil Paint/Water Brushes


As per my project requirement, I wanted to create a brush which will give me a effect like oil/water painting. Please find attached snaps of it. I've taken this snap from Microsoft Paint Application. Microsoft Paint provides different brushes and one of them is Oil Brush.

After keen observation, I noticed that the complete pattern used in microsoft paint is hard-coded. For every stoke(with any color) it gets repeated.

My requirement are flexible, either i can implement fixed brush style or it can be random pattern.

I wanted to know, which API to use so that my solid fill line will look like a oil paint or water color painting.

I've created a sample application which uses NSBezierPath to draw a path but NSBezierPath doesn't have any functionalities using which i can provide such effects to it.

Regards Omkar


Solution

  • I solved it using NSColor class API

    NSImage* anImage; // Create an image with any brush pattern
    [[NSColor colorWithPatternImage:anImage]
    

    I created a small image say 25x25 out of a oil paint brush pattern created in MS Paint application and provided the path to anImage object.

    in drawRect before drawing the NSBezierPath I set the color using above image object.