我使用以下函数在MKMapView的UIImage快照上绘制折线。该功能有效,但对我的目的来说太慢了。反正是为了加快速度吗?
func drawLineOnImageFromLocations(image: UIImage, snapshot: MKMapSnapshot,
polylineLocations: [CLLocation], color: CGColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(image.size, true, 0)
// draw original image into the context
image.draw(at: CGPoint.zero)
// get the context for CoreGraphics
guard let context = UIGraphicsGetCurrentContext() else {
return image
}
context.beginPath()
context.setLineWidth(10)
context.setStrokeColor(color)
let coordinates = polylineLocations.map{$0.coordinate}
var points = [CGPoint]()
for coordinate in coordinates {
let point = snapshot.point(for: coordinate)
points.append(point)
}
context.addLines(between: points)
context.strokePath()
// get the image from the graphics context
let resultImage = UIGraphicsGetImageFromCurrentImageContext()
// end the graphics context
UIGraphicsEndImageContext()
return resultImage!
}
答案 0 :(得分:1)
结果是呼唤:
var count = 0;
.......
JSZipUtils.getBinaryContent(imageUrl, function (err, data) {
if (err) {
// throw err; // or handle the error
console.log(err);
}
else {
zip.file(fileName, data, { binary: true });
count++;
if (count == selectedImages.length) {
zip.generateAsync({ type: "blob" }).then(function (base64) {
// window.location.replace("data:application/zip;base64," + base64);
saveAs(base64, `archive.zip`);
console.log("inner");
});
}
}
});
是一项非常昂贵的操作。如果你能重构你的代码只是一次调用它会大大加快速度。