0

我正在开发一个 pdf 注释应用程序,到目前为止,我可以使用“PDFAnnotationSubtype.stamp”中的图像画一条线。

图片: 在此处输入图像描述

使用下面的代码:

public class ImageAnnotation: PDFAnnotation{ 

 init(with image: UIImage!, forBounds bounds: CGRect, withProperties properties: [AnyHashable : Any]?) {
    super.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)

    self._image = image
}

override public func draw(with box: PDFDisplayBox, in context: CGContext) {
    guard let cgImage = self._image?.cgImage else { return }
    context.draw(cgImage, in: self.bounds)
}
}

结果: 在此处输入图像描述

使用这种方法,我最终在每个 CGpoint 添加图像(换句话说,每个 cgpoint 都是单独的 PDFAnnotation)。如何将整个路径制作为单个笔划/单个注释,这样当我尝试擦除时,应该清除整个路径而不是只有几个 cgpoint/像素。

4

1 回答 1

1

在搜索了几个资源后发现我们可以使用“CGPattern”来纹理线条。

参考: https ://developer.apple.com/documentation/coregraphics/cgpattern

对于尝试此操作的任何其他人,请确保使用“填充”和“描边”模式来玩“drawingPath”。

于 2021-01-11T08:42:32.833 回答