David Homes
David Homes

Reputation: 2796

MKMapView -> to UIImage -> to NSData

for a MKMapView : UIView

how could i convert the content of the mkmapview to a uiimage?

although from the mkmapview the end goal (or primary main objective, if you know what i mean) is a NSData var which I can then attach to an email with mimeType "image/png"

kinda of grabbing a screenshot of whatever the MKMapview is showing at any given moment

putting that on a (UIImage)mapImage

NSData *imageData= UIImagePNGRepresentation(mapImage);

any tips?

thanks in advance

Upvotes: 9

Views: 1485

Answers (1)

sudo rm -rf
sudo rm -rf

Reputation: 29524

Why not try something like this (untested)?

UIGraphicsBeginImageContext(mapView.frame.size);
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData *mapData = UIImagePNGRepresentation(mapImage);
[mapData writeToFile:[self myFilePath:@"yourMap.png"] atomically:YES];

Upvotes: 11

Related Questions