I have a view that has a UIImage
and a DrawView
as subviews. The draw view responds to touches and creates a UIBezierPath
for drawing on the image. When the user accepts their change I need to merge the underlying UIImage
and any UIBezierPath
's created into a single UIImage
.
Asked
Active
Viewed 416 times
0

CWitty
- 4,488
- 3
- 23
- 40
1 Answers
4
Make that UIBazierPath
a public property of your DrawView
, and keep updating it when user is drawing from within DrawView
. When user hits the Accept button, use following code to simply Create a UIImageContext
and draw both, the sourceImage
and bezierPath
over the context. Finally take whatever is drawn on the context in a resultImage
.
UIBezierPath *path = drawView.Path // Your Bezier Path in DrawView
UIImage *sourceImage = sourceImageView.image; // Your Source Image from ImageView.
UIImage *resultImage = nil;
UIGraphicsBeginImageContext(sourceImage.size);
[sourceImage drawInRect:(CGRect){CGPointZero, sourceImage.size}];
[path stroke]; //Fill or Stroke path as you need.
[path fill];
resultImage = UIGraphicsGetImageFromCurrentImageContext(); //taking the merged result from context, in a new Image. This is your required image.
UIGraphicsEndImageContext();
//Use resultImage as you want.

Sabir Ali
- 475
- 2
- 16
-
Could you please add more details about your answer? – abarisone Apr 12 '15 at 15:17
-
I used this in combination with http://stackoverflow.com/a/14119250/531479 and it was what I needed. – CWitty Apr 13 '15 at 14:33