Question

I want to implement Advanced image markup in UIIMageView. Currently image mark up is working fine. I'm adding UIView(Advanced markup) programatically as a subview. So when I save the UIImageView image, SubViews are not getting saved.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.imageView];


    UIView *rectangle = [[UIView alloc] initWithFrame:CGRectIntegral(CGRectMake(touchLocation.x,
                                                                                touchLocation.y,
                                                                                0,
                                                                                0))];
    rectangle.backgroundColor = [UIColor blackColor];
    rectangle.layer.cornerRadius = 10.0f;
    rectangle.layer.shadowColor = [UIColor blackColor].CGColor;
    rectangle.layer.shadowOffset = CGSizeMake(0.0f, 3.0f);
    rectangle.layer.shadowOpacity = 0.4;
    rectangle.layer.shadowRadius = 1.0;
    //rectangle.layer.shadowPath = rectangleShadowPath;

    JSBadgeView *badgeView = [[JSBadgeView alloc] initWithParentView:rectangle alignment:JSBadgeViewAlignmentTopRight];
    badgeView.badgeText = [NSString stringWithFormat:@"%d",i];
    i = i + 1;
    [self.imageView addSubview:rectangle];
    [self.imageView sendSubviewToBack:rectangle];

     [self saveImage:self.imageView.image WithImgName:@"abc"];
}

Following is my Advanced mark up image.

enter image description here

So how can I save UIImageView's image with subviews(Red color dot mark ups)?

Was it helpful?

Solution

UIGraphicsBeginImageContext(CGSizeMake(self.imageView.frame.size.width, self.imageView.size.height));
CGContextRef context = UIGraphicsGetCurrentContext();
[self.imageView.layer renderInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

 [self saveImage:screenShot WithImgName:@"abc"];

OTHER TIPS

You can do it by taking screenshot of the UIImageView.

- (UIImage *)snapshot
{
    UIImage* snapShot = nil;
    UIGraphicsBeginImageContext(imageView.frame.size);
    {
        [imageView.layer renderInContext: UIGraphicsGetCurrentContext()];
        snapShot = UIGraphicsGetImageFromCurrentImageContext();

    }

    UIGraphicsEndImageContext();
    return snapShot;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top