Creating an MKMapSnapshotter with an MKPolylineRenderer

前端 未结 1 1472
心在旅途
心在旅途 2021-01-11 13:45

I thought iOS 7\'s MKMapSnapshotters would be a simple way to take a snapshot of an MKMapView, the benefit is that you can do it without loading th

相关标签:
1条回答
  • 2021-01-11 14:32

    Just had the same problem, this code seems to work:

    UIImage * res = nil;
    UIImage * image = snapshot.image;
    
    UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
    [image drawAtPoint:CGPointMake(0, 0)];
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetStrokeColorWithColor(context,  [COLOR_FLASHBLUE CGColor]);
    CGContextSetLineWidth(context,2.0f);
    CGContextBeginPath(context);
    
    CLLocationCoordinate2D coordinates[[polyline pointCount]];
    [polyline getCoordinates:coordinates range:NSMakeRange(0, [polyline pointCount])];
    
    for(int i=0;i<[polyline pointCount];i++)
    {
        CGPoint point = [snapshot pointForCoordinate:coordinates[i]];
    
        if(i==0)
        {
            CGContextMoveToPoint(context,point.x, point.y);
        }
        else{
            CGContextAddLineToPoint(context,point.x, point.y);
    
        }
    }
    
    CGContextStrokePath(context);
    
    res = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    0 讨论(0)
提交回复
热议问题