有没有办法拍摄mapView的截图并包含折线?我相信我需要在MKSnapShotter返回的图像上绘制CGPoint,但我不确定如何这样做.
目前的代码
func takeSnapshot(mapView: MKMapView, withCallback: (UIImage?, NSError?) -> ()) {
let options = MKMapSnapshotOptions()
options.region = mapView.region
options.size = mapView.frame.size
options.scale = UIScreen.main().scale
let snapshotter = MKMapSnapshotter(options: options)
snapshotter.start() { snapshot, error in
guard snapshot != nil else {
withCallback(nil, error)
return
}
if let image = snapshot?.image{
withCallback(image, nil)
for coordinate in self.area {
image.draw(at:snapshot!.point(for: coordinate))
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要在UIImage中绘制/涂鸦一行,如上图所示,我在UIView上看到很多教程涂鸦线但在UIImage中没有.
用户在图像上涂鸦后,我想将其保存为新图像(具有线条的图像).我怎么在Swift中做到这一点?
我只能在UIView上找到绘制线而不是在UIImage中用于绘制UIView就像这个在youtube教程http://youtube.com/watch?v=gbFHqHHApC4中,我将其更改为继承DrawView到UIImageView
struct Stroke {
let startPoint : CGPoint
let endPoint : CGPoint
let strokeColor : CGColor
}
class DrawView : UIImageView {
var isDrawing = false
var lastPoint : CGPoint!
var strokeColor : CGColor! = UIColor.black.cgColor
var strokes = [Stroke]()
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard !isDrawing else { return }
isDrawing = true
guard let touch = touches.first else {return}
let currentPoint = touch.location(in: self)
lastPoint = currentPoint
print(currentPoint)
}
override …Run Code Online (Sandbox Code Playgroud)