Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 255
David Homes Avatar asked May 09 '11 04:05

David Homes


People also ask

How do I find my UIImage path?

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.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.

What is UIImage?

An object that manages image data in your app.

How do you declare UIImage in Objective C?

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.


1 Answers

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];
like image 64
sudo rm -rf Avatar answered Sep 29 '22 02:09

sudo rm -rf