Saturday, April 26, 2025
HomeiOS Developmentios - The right way to annotate rounded, aspect-fill picture in PDFView...

ios – The right way to annotate rounded, aspect-fill picture in PDFView (swift PDFKit)

[ad_1]

I’m engaged on annotate a picture to an present PDFView.
That is my present state:
enter image description here

And beneath is my desired state:
enter image description here

In a single sentence, I wish to obtain:

  1. a rounded corder of my picture annotation
  2. picture must also keep the unique facet ratio
    I’ve tried and searched many sources however none of them works.

Under is my present code:

class PDFImageAnnotation: PDFAnnotation {

var picture: UIImage?

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

override func draw(with field: PDFDisplayBox, in context: CGContext) {
    tremendous.draw(with: field, in: context)

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

}

Implementation in ViewDidLoad:

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

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments