I ma trying to save image with my silly drawing ,but when i save the image only original image getting saved.
This is my image saving code:
UIImageWriteToSavedPhotosAlbum(_imgShow.image,
nil,
nil,
nil);
This is my UIImageView custom class:
-(void)awakeFromNib
{
// drawingView=[[UIView alloc]initWithFrame:self.bounds];
// drawingView.backgroundColor=[UIColor clearColor];
// [self addSubview:drawingView];
clearBeizer=[[NSMutableArray alloc]init];
[self updateMask];
}
-(void)updateMask
{
CALayer *maskLayer=[CALayer layer];
maskLayer.geometryFlipped=YES;
maskLayer.contents=(id)self.image.CGImage;
switch (self.contentMode)
{
case UIViewContentModeScaleToFill:
maskLayer.contentsGravity = kCAGravityResize;
break;
case UIViewContentModeScaleAspectFit:
maskLayer.contentsGravity = kCAGravityResizeAspect;
break;
case UIViewContentModeScaleAspectFill:
maskLayer.contentsGravity = kCAGravityResizeAspectFill;
break;
case UIViewContentModeCenter:
maskLayer.contentsGravity = kCAGravityCenter;
break;
case UIViewContentModeTop:
maskLayer.contentsGravity = kCAGravityTop;
break;
case UIViewContentModeBottom:
maskLayer.contentsGravity = kCAGravityBottom;
break;
case UIViewContentModeLeft:
maskLayer.contentsGravity = kCAGravityLeft;
break;
case UIViewContentModeRight:
maskLayer.contentsGravity = kCAGravityRight;
break;
case UIViewContentModeTopLeft:
maskLayer.contentsGravity = kCAGravityTopLeft;
break;
case UIViewContentModeTopRight:
maskLayer.contentsGravity = kCAGravityTopRight;
break;
case UIViewContentModeBottomLeft:
maskLayer.contentsGravity = kCAGravityBottomLeft;
break;
case UIViewContentModeBottomRight:
maskLayer.contentsGravity = kCAGravityBottomRight;
break;
default:
break;
}
maskLayer.frame=self.bounds;
// drawingView.layer.mask=maskLayer;
self.layer.mask=maskLayer;
}
-(void)setImage:(UIImage *)image
{
[super setImage:image];
[self updateMask];
}
-(void)layoutSubviews
{
[super layoutSubviews];
// drawingView.frame=self.bounds;
// drawingView.layer.mask.frame=drawingView.bounds;
self.frame=self.bounds;
self.layer.mask.frame=self.bounds;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
startingPoint = [touch locationInView:self];
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
touchPoint = [touch locationInView:self];
if (!CGPointEqualToPoint(startingPoint, CGPointZero))
{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)];
[path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
if([UIDevice currentDevice].userInterfaceIdiom ==UIUserInterfaceIdiomPad)
{
shapeLayer.lineWidth = 7.0;
}
else
{
shapeLayer.lineWidth = 5.0;
}
shapeLayer.fillColor = [[UIColor redColor] CGColor];
[self.layer addSublayer:shapeLayer];
[clearBeizer addObject:shapeLayer];
}
startingPoint=touchPoint;
// [arrLayer addObject:shapeLayer];
NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y);
}
This is my custom class.
You are just changing the rendering of the image, not the data of the image itself, but then writing that data and expect it to reflect your view's rendering.
You can use snapshotViewAfterScreenUpdates:
and the results from this question do manage what you actually want to archieve.