【问题标题】:How to annotate rounded, aspect-fill image in PDFView (swift PDFKit)如何在 PDFView (swift PDFKit) 中注释圆角填充图像
【发布时间】:2022-01-01 14:21:58
【问题描述】:

我正在为现有的 PDFView 注释图像。 这是我目前的状态:

以下是我想要的状态:

一句话,我想实现:

  1. 我的图像注释的圆边
  2. 图像也应该保持原来的纵横比 我尝试并搜索了许多来源,但没有一个有效。

以下是我当前的代码:

class PDFImageAnnotation: PDFAnnotation {

var image: UIImage?

convenience init(_ image: UIImage?, bounds: CGRect, properties: [AnyHashable : Any]?) {
    self.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)
    self.image = image
}

override func draw(with box: PDFDisplayBox, in context: CGContext) {
    super.draw(with: box, in: context)

    // Drawing the image within the annotation's bounds.
    guard let cgImage = image?.cgImage else { return }
    context.draw(cgImage, in: bounds)
}

}

ViewDidLoad 中的实现:

if let image = pet.picture?.getImage() {
        let imageAnnotation = PDFImageAnnotation(image, bounds: CGRect(x: 80, y: 1100, width: 300, height: 300), properties: nil)
        pdfView.currentPage?.addAnnotation(imageAnnotation)
    }

任何建议都会有所帮助,因为我现在处于死胡同,非常感谢!

【问题讨论】:

    标签: ios swift xcode ios-pdfkit apple-pdfkit


    【解决方案1】:

    好的,我想通了,原来我应该先将图像剪辑为圆形格式,然后使用此扩展名将其注释到 PDF:https://stackoverflow.com/a/64981764/11079192

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      相关资源
      最近更新 更多