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
Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
An object that manages image data in your app.
For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in . h file and allocated in init method, I need to set image in viewDidLoad method.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With