Haris Hussain
Haris Hussain

Reputation: 2581

Overlays are not captured in MKMapView ScreenShot taken programmatically

I have been trying to take screenshot on MKMapView on which i am drawing user location draw a path using the BreadCrumbs classes CrumbPath and CrumbPathView overlay and overlay view classes.

Here is the code i am using to get the screen Shot:

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, [UIScreen mainScreen].scale);

else
    UIGraphicsBeginImageContext(self.view.frame.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIImage * croppedImage = [Utils cropImage:viewImage withFrame:_map.frame];    
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil);

ScreenShot i am trying to get Should look like this:

enter image description here

But the ScreenShot i get looks like this:

enter image description here

Here you can notice the Blue line (User Location Path) is not there in the ScreenShot.

Can anyone please help me suggest whats the solution or what am i doing wrong here?

Thanks Everyone.

Upvotes: 2

Views: 969

Answers (1)

Paras Joshi
Paras Joshi

Reputation: 20551

Use this my custom method it return image of current view..

- (UIImage *)captureView {

   //hide controls if needed
    CGRect rect = [self.view bounds];

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;

}

Upvotes: 1

Related Questions