Reputation: 2581
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:
But the ScreenShot i get looks like this:
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
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