开发者

MKMapView -> to UIImage -> to NSData

开发者 https://www.devze.com 2023-03-04 23:08 出处:网络
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

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

精彩评论

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

关注公众号