Skip to content

Instantly share code, notes, and snippets.

@abock
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abock/bd946d3fe7436bce79c0 to your computer and use it in GitHub Desktop.
Save abock/bd946d3fe7436bce79c0 to your computer and use it in GitHub Desktop.
using System;
using System.Runtime.InteropServices;
namespace MonoMac.CoreGraphics
{
public static class CGPathExtensions
{
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPathCreateMutableCopy (IntPtr source);
[DllImport (Constants.CoreGraphicsLibrary)]
static extern void CGPathRelease (IntPtr source);
[DllImport (Constants.CoreGraphicsLibrary)]
unsafe static extern IntPtr CGPathCreateCopyByStrokingPath (
IntPtr path,
CGAffineTransform *transform,
float lineWidth,
CGLineCap lineCap,
CGLineJoin lineJoin,
float miterLimit
);
public unsafe static CGPath CopyByStrokingPath (this CGPath path, CGAffineTransform transform,
float lineWidth, CGLineCap lineCap, CGLineJoin lineJoin, float miterLimit)
{
var copy = CGPathCreateCopyByStrokingPath (path.Handle,
&transform, lineWidth, lineCap, lineJoin, miterLimit);
// this will call CGPathRetain, which we don't want
var mutable = CGPathCreateMutableCopy (copy);
CGPathRelease (mutable); // so immediately release it
CGPathRelease (copy);
return mutable;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment