开发者

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 开发者_StackOverflowthen 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


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜