0

What's the easiest and least performance intensive way to achieve this?

Right now i have a UIBezierPath with over 60000 lines. I want to create an image from it that will later be moved around on-screen and stretched.

HSNN
  • 531
  • 1
  • 6
  • 14
  • See this questions first answer: http://stackoverflow.com/questions/11739816/ios-uiimage-image-upside-down but instead of drawing a UIImage in into the context, draw your path in the context – V1ru8 Jun 26 '13 at 13:30
  • but how do I draw onto that image? CGContextDrawPath? or should I just use [path stroke] and it'll be drawn onto the image? – HSNN Jun 26 '13 at 14:11
  • http://stackoverflow.com/questions/17408209/how-to-create-a-image-with-uibezierpath/40908425#40908425 – Shrawan Dec 01 '16 at 10:49

1 Answers1

9

Just create a graphics context and draw your path into it, like this:

UIGraphicsBeginImageContextWithOptions(path.bounds.size, NO, 0.0); //size of the image, opaque, and scale (set to screen default with 0)
[path fill]; //or [path stroke]
UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

If you're planning on moving the image around, you'll need to draw it into your view, or preferably a UIImageView that's a subview of that view. This is faster than redrawing your view every time the user moves his finger.

Hope this helps!

architectpianist
  • 2,562
  • 1
  • 19
  • 27
  • the first line has a warning on Xcode: `Implicit declaration of function 'UIGraphicsCreateImageContextWithOptions' is invalid` and building fails: `Undefined symbols for architecture i386: "_UIGraphicsCreateImageContextWithOptions"` – HSNN Jun 26 '13 at 15:34