地圖快照截圖
// 截圖附加選項(xiàng)
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
// 設(shè)置截圖區(qū)域(在地圖上的區(qū)域,作用在地圖)
options.region = self.mapView.region;
// options.mapRect = self.mapView.visibleMapRect;
// 設(shè)置截圖后的圖片大小(作用在輸出圖像)
options.size = self.mapView.frame.size;
// 設(shè)置截圖后的圖片比例(默認(rèn)是屏幕比例, 作用在輸出圖像)
options.scale = [[UIScreen mainScreen] scale];
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot * _Nullable snapshot, NSError * _Nullable error) {
if (error) {
NSLog(@"截圖錯(cuò)誤:%@",error.localizedDescription);
}else
{
// 設(shè)置屏幕上圖片顯示
self.snapshootImageView.image = snapshot.image;
// 將圖片保存到指定路徑(此處是桌面路徑,需要根據(jù)個(gè)人電腦不同進(jìn)行修改)
NSData *data = UIImagePNGRepresentation(snapshot.image);
[data writeToFile:@"/Users/wangshunzi/Desktop/snap.png" atomically:YES];
}
}];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者