我想从我的 Mapview 的特定位置截屏。我使用了以下代码。它工作正常,但屏幕截图有点模糊。我想要高分辨率的屏幕截图。请检查我的代码。谢谢。!
func takeSnapShotForSaveSearch(_ centerPoint: CLLocationCoordinate2D) {
var newRegion = mapHomes.region
UIView.animate(withDuration: 0.0, animations: {() -> Void in
let region = MKCoordinateRegionMakeWithDistance(centerPoint, 500.0, 500.0)
// region.center = centerPoint
// region.span.latitudeDelta = 1.0
// region.span.longitudeDelta = 1.0
newRegion = region
}, completion: {(_ finished: Bool) -> Void in
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let fileName = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("SaveSearch.png").absoluteString
let options = MKMapSnapshotOptions()
options.region = newRegion
options.showsBuildings = false
options.showsPointsOfInterest = false
options.size = CGSize(width: 250.0, height: 250.0)
let snapshotter = MKMapSnapshotter(options: options)
snapshotter.start(completionHandler: { (snapShot, error) in
let image = snapShot?.image
if image != nil {
let data = UIImagePNGRepresentation(image!)
let fileURL = URL(string: fileName)
do {
try data?.write(to: fileURL!)
} catch {
print(error)
}
}
})
})
}